4.3、改变 Checkbutton 的显示文本
# text:显示的文本内容
# command:指定的事件处理函数
from Tkinter import *
def callCheckbutton():
#改变 v 的值,即改变 Checkbutton 的显示值
v.set('check Tkinter')
root = Tk()
v = StringVar()
v.set('check python')
#绑定 v 到 Checkbutton 的属性 textvariable
Checkbutton(root,
text = 'check python',
textvariable = v,
command = callCheckbutton
).pack()
root.mainloop()
代码
from tkinter import *
def callC():
v.set("选择了Tkinter")
quehui = Tk()
v = StringVar()
v.set("选择了Python")
Checkbutton(quehui,
text = "选择了Python",
textvariable = v,
command = callC
).pack()
quehui.mainloop()



浙公网安备 33010602011771号