我在「實驗」與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中的局部變量。 –