【发布时间】:2020-08-05 14:19:18
【问题描述】:
我有这个代码:
from tkinter import *
root = Tk()
root = root
root.title("1")
root.geometry('600x650')
def click():
b.destroy()
b = (1, 2, 3, 4, 5)
for i in b:
b = Button(root, text=i, command=click)
b.pack()
print("success")
root.mainloop()
我需要销毁按钮,我点击了它,但它销毁了最后生成的按钮。
请不要推荐这样的代码:
from tkinter import *
root = Tk()
root = root
root.title("1")
root.geometry('600x650')
def click1():
button1.destroy()
def click2():
button2.destroy()
button1 = Button(root, text="1", command=click1)
button2 = Button(root, text="2", command=click2)
button1.pack()
button2.pack()
print("success")
root.mainloop()
我需要每个按钮都能自行关闭。
【问题讨论】:
-
您只是一遍又一遍地创建一个按钮。您没有像预期的那样创建按钮列表。
标签: python-3.x tkinter