当我们改变一个组件后,其他组件一起变化怎么做呢?下面是一个例子
from tkinter import Tk, Checkbutton, Labelfrom tkinter import StringVar, IntVarroot = Tk()text = StringVar()text.set('old')status = IntVar()def change(): if status.get() == 1: # if clicked text.set('new') else: text.set('old')cb = Checkbutton(root, variable=status, command=change)lb = Label(root, textvariable=text)cb.pack()lb.pack()root.mainloop()
注意这些代码是python3.6下,如果是python2.7 应该用Tkinter模块