【发布时间】:2021-03-23 19:08:45
【问题描述】:
我是 Tkinter 的新手,不知道如何通过将它们组织在一个列表中来创建多个按钮。我能够显示一个按钮,但是当我尝试创建多个时,它不起作用,而是创建一个空白页面。
from tkinter import *
from V2cboard import *
import time
#blueLength=len(blueTokens) # This is the num of blue tokens left on board
#redLength=len(redTokens) # This is the num of red tokens left on board
DispTXT=["Play as Red!","Play as Blue!","Let the Computer play!","Two players!"]
button=[None]
root=Tk()
for i in range(4):
button[i] = Button(root, text=DispTXT[i], command=boardWindow(i))
button[i].pack()
root.mainloop()
请理解我是编码和 Tkinter 的新手。
我预计会在窗口中创建 4 个单独的按钮,每个按钮都显示上面列表中的文本。然后,当单击一个时,它会将数字 (i) 发送到我的功能 boardWindow 以执行其他操作。我无法让按钮出现,所以我认为这可能是语法错误或者我误解了 Button 函数的工作原理?我得到了错误
can't invoke "button" command: application has been destroyed
当我尝试创建按钮时?
【问题讨论】: