我在“实验”与Tkinter的新东西(我与它一个初学者)和我做,只是为了好玩很明显,这个应用程序:删除网格元素 - Tkinter的
from tkinter import *
def text() :
if checking :
content.grid_forget()
else :
content = Label(root, text = txt.get()).grid(row = 3, column = 0)
def check() :
checking = True
text()
root = Tk()
txt = StringVar()
checking = False
bt1 = Button(root, text = "Print me!", command = text)
bt2 = Button(root, text = "Clear!", command = check)
txt1 = Entry(root, textvariable = txt)
row = 0
for i in [bt1, bt2, txt1] :
i.grid(row = row, column = 0)
row+=1
root.mainloop()
我的问题是,为什么ISN “清除”按钮有效吗?
'checking'是check中的局部变量。 –