本帖最后由 qiuyouzhi 于 2020-3-18 16:57 编辑
这代码会报错啊,你那个global写的不对吧
得这样改:from tkinter import *
from tkinter import colorchooser
import win32api,win32con
root = Tk()
root.title("甲鱼画板改良")
filename,box,box2 = '','',''
sw = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)
sh = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
x = sw / 1.5
y = sh / 1.5
w = Canvas(root, width=x, height=y)
w.pack()
def callback():
fileName = colorchooser.askcolor(title = "请选择颜色")
box=",".join(map(str, fileName))
box2 = (box[-7:])
Button(root, text="选择颜色", command=callback).pack()
def paint(event):
x1, y1 = (event.x - 1.5), (event.y - 1.5)
x2, y2 = (event.x + 1.5), (event.y + 1.5)
w.create_oval(x1, y1, x2, y2, fill=box2)
w.bind("<B1-Motion>", paint)
Label(root, text="按住鼠标左键并移动,开始绘制你的理想蓝图吧......").pack(side=BOTTOM)
mainloop()
#此程序需要安装Pywin32模块
|