我正在做一个教程来向别人解释事情。在这个教程中,我正在尝试制作一个python程序(类似于画图应用程序)。
我们都用在窗户上。用钢笔,刷子和画形状,如方形,圆圈,并有一个选项的彩色皮克选择颜色绘制。
我已经尝试使用from tkinter import choosecolor
在python中创建类似于绘图的软件。
但是这样的话,它只能在一张平纹画布上画。
但是我不想在画布上画画,我想在制作教程的时候在直播屏幕上画它。
示例图像如下所示
我试着做一个像这样的gui窗口来选择颜色和笔工具在屏幕上画画(eg.desktop,window等)。
有人能给我一些建议,如何在我的桌面屏幕或任何窗口上这样画。
发布于 2020-04-01 12:02:39
虽然在你的视频中,似乎“直接在屏幕上画画".Actually,但我认为它没有。
有一个简单的“在屏幕上绘图”的例子,您可以修改它:
import tkinter as tk
from PIL import ImageGrab,ImageTk
import ctypes
ctypes.windll.shcore.SetProcessDpiAwareness(2) # windows 10
class ToolWin(tk.Toplevel):
def __init__(self):
tk.Toplevel.__init__(self)
self._offsetx = 0
self._offsety = 0
self.wm_attributes('-topmost',1)
self.penSelect = tk.BooleanVar()
self.overrideredirect(1)
self.geometry('200x200')
self.penModeId = None
self.bind('<ButtonPress-1>',self.clickTool)
self.bind('<B1-Motion>',self.moveTool) # bind move event
draw = tk.Checkbutton(self,text="Pen",command=self.penDraw,variable=self.penSelect)
draw.pack()
cancel = tk.Button(self,text="Quit",command=root.destroy)
cancel.pack()
def moveTool(self,event):
self.geometry("200x200+{}+{}".format(self.winfo_pointerx()-self._offsetx,self.winfo_pointery()-self._offsety))
def clickTool(self,event):
self._offsetx = event.x
self._offsety = event.y
def penDraw(self):
if self.penSelect.get():
self.penModeId = root.bind("<B1-Motion>",Draw)
else:
root.unbind('<B1-Motion>',self.penModeId)
def Draw(event):# r = 3
fullCanvas.create_oval(event.x-3,event.y-3,event.x+3,event.y+3,fill="black")
def showTool(): # the small tool window
toolWin = ToolWin()
toolWin.mainloop()
root = tk.Tk()
root.state('zoomed')
root.overrideredirect(1)
fullCanvas = tk.Canvas(root)
background = ImageTk.PhotoImage(ImageGrab.grab(all_screens=True)) # show the background,make it "draw on the screen".
fullCanvas.create_image(0,0,anchor="nw",image=background)
fullCanvas.pack(expand="YES",fill="both")
root.after(100,showTool)
root.mainloop()
此外,还可以通过拖动工具栏来移动它。(我想你快完成了。)
https://stackoverflow.com/questions/60967643
复制相似问题