赞
踩
此功能由3个.py文件实现,分别为:test00.py、screenshot.py、py_tool.py;实现鼠标附近局部放大,未截图部分半透明,鼠标控制键盘精准截图,鼠标框选后自动保存截图,按下esc键退出截图;
import tkinter as tk
from common import py_tool
from common.screenshot import Screenshot
scale = py_tool.get_screen_scale_rate()
py_tool.eliminate_scaling_interference()
top = tk.Tk()
Screenshot(top, scale)
top.mainloop()
# coding:utf-8 import time import tkinter as tk import keyboard from PIL import ImageGrab, ImageTk, Image from common import py_tool # 截图类 class Screenshot: def __init__(self, top, scale): """---------------------------------------------------系统设置""" # 获取屏幕缩放比例; self.scale = scale # 排除缩放干扰; py_tool.eliminate_scaling_interference() # 初始化关闭窗口标志; self.win_close = 0 "---------------------------------------------------初始窗口" # 最小化主窗口; top.iconify() # 实例化主窗口; self.top_screenshot = tk.Toplevel(top) # 不显示标题栏; self.top_screenshot.overrideredirect(True) # 窗口长和宽; self.width_win = self.top_screenshot.winfo_screenwidth() self.height_win = self.top_screenshot.winfo_screenheight() # 设置主窗口大小和位置; self.top_screenshot.geometry(str(int(self.width_win)) + 'x' + str(int(self.height_win)) + '+' + str(int((self.top_screenshot.winfo_screenwidth() - self.width_win) / 2)) + '+' + str(int((self.top_screenshot.winfo_screenheight() - self.height_win) / 2))) # 设置窗口背景颜色,鼠标样式; self.top_screenshot.config(bg='', cursor='crosshair') "---------------------------------------------------全屏截图" # 实时放大会把雾窗口和截图边框放大,不美观,速度慢,放大已完成截图的图片; time.sleep(0.5) # 全屏截图; self.img_screenshot = ImageGrab.grab( (0, 0, self.top_screenshot.winfo_screenwidth(), self.top_screenshot.winfo_screenheight())) # 保存截图; self.img_screenshot.save('test00.png') # 打开截图; self.img_screenshot = Image.open('test00.png') "---------------------------------------------------窗口边框" # 初始化边框画布边框宽度; self.canvas_frame_frame_width = 1 * self.scale # 创建上边框画布; canvas_frame_up = tk.Canvas(self.top_screenshot, width=self.width_win, height=self.canvas_frame_frame_width, bg='yellow', highlightthickness=self.canvas_frame_frame_width, highlightbackground='yellow') # 设置上边框画布位置; canvas_frame_up.place(relx=0.5, rely=0, anchor=tk.CENTER) canvas_frame_down = tk.Canvas(self.top_screenshot, width=self.width_win, height=self.canvas_frame_frame_width + 1, bg='yellow', highlightthickness=self.canvas_frame_frame_width, highlightbackground='yellow') canvas_frame_down.place(relx=0.5, rely=1, anchor=tk.CENTER) canvas_frame_left = tk.Canvas(self.top_screenshot, width=self.canvas_frame_frame_width, height=
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。