Sid*_*iya 1 tkinter python-2.7
我需要一个清除选中复选框的按钮.请有人指导我.提前致谢.
import Tkinter
from Tkinter import*
top = Tkinter.Tk()
CheckVar1=IntVar()
CheckVar2=IntVar()
C1=Checkbutton(top, text = "Music", variable = CheckVar1,
onvalue = 1, offvalue = 0, height=5,
width = 20,activebackground="red",bg="green")
C2=Checkbutton(top, text = "Video", variable = CheckVar2,
onvalue = 1, offvalue = 0, height=5,
width = 20)
C1.pack()
C2.pack()
B = Tkinter.Button(top, text ="Hello",activebackground="red",
,bd=3,bg="green",width=5) #Button
B.pack()
top.mainloop()
Run Code Online (Sandbox Code Playgroud)
创建一个将CheckVar1和CheckVar2的值设置为0的函数.
def clear():
CheckVar1.set(0)
CheckVar2.set(0)
Run Code Online (Sandbox Code Playgroud)
然后只需将其与按钮链接即可.
B = Tkinter.Button(top, text ="Hello",activebackground="red",
bd=3,bg="green",width=5, command = clear) #Button
Run Code Online (Sandbox Code Playgroud)
顺便说一句,你这里有一个额外的逗号.