A1exxx 发表于 2021-2-3 10:36:57

py中tkinter问题

from tkinter import *
root=Tk()
w=Canvas(root,width=200,height=100)
w.pack()
line1=w.create_line(0,50,200,50,fill='blue')
line2=w.create_line(100,0,100,100,fill='red',dash=(4,4))
rect1=w.create_rectangle(50,25,150,75,fill='green')
w.coords(line1,0,25,200,25)
w.itemconfig(rect1,fill='red')
w.delete(line2)

Button=(root,text="删除全部",command=(lambda x=ALL:w.delete(x))).pack()


mainloop()

运行提示text后面等号变为红色,求大神指点

qiuyouzhi 发表于 2021-2-3 10:39:15

为什么Button和括号中间还有个等号呢..删了就好了

from tkinter import *
root=Tk()
w=Canvas(root,width=200,height=100)
w.pack()
line1=w.create_line(0,50,200,50,fill='blue')
line2=w.create_line(100,0,100,100,fill='red',dash=(4,4))
rect1=w.create_rectangle(50,25,150,75,fill='green')
w.coords(line1,0,25,200,25)
w.itemconfig(rect1,fill='red')
w.delete(line2)

Button(root, text = "删除全部",command = (lambda x=ALL:w.delete(x))).pack()


mainloop()
页: [1]
查看完整版本: py中tkinter问题