Python 3.x 在Python3中使用tkinter按下按钮后,如何删除按钮?
我正在尝试用Tkinter制作一个游戏,我正在尝试移除按钮 我使用的代码是:Python 3.x 在Python3中使用tkinter按下按钮后,如何删除按钮?,python-3.x,tkinter,Python 3.x,Tkinter,我正在尝试用Tkinter制作一个游戏,我正在尝试移除按钮 我使用的代码是: from tkinter import * from random import * def ct(): textA.destroy() tAb.destroy() window = Tk() textA = Text(window, width = 15, height = 1) textA.insert(END, 'Choose a type.') textA.config(state="dis
from tkinter import *
from random import *
def ct():
textA.destroy()
tAb.destroy()
window = Tk()
textA = Text(window, width = 15, height = 1)
textA.insert(END, 'Choose a type.')
textA.config(state="disabled")
tAb = Button(window, text = 'filler', command = ct)
我不想把它改得太多。这段代码与您期望的有什么不同?这是一个错误吗?破坏错误的东西?在错误的时间销毁它?还有什么?首先,您的代码没有调用任何布局函数,例如
文本
和按钮
小部件上的grid()
或pack()
,因此它们不会显示。其次,代码没有调用window.mainloop()
。您的代码将文本
和按钮
小部件一起销毁在ct()
函数中。如果您只想删除按钮,只需调用tAb.destroy()
。