from random import*
from tkinter import*
players=['wq','qwe','qwe']
players_to_random=[]
window = Tk()
window.title("Game is ON")
w= Label(window, bg="yellow")
def onclick():
players_to_random.append(text)
print(players_to_random)
def showButtons():
for i in players:
btn = Button(window, text=i command=onclick)
btn.pack(side=LEFT)
showButtons()
我得到了Error命令无效的语法,但据我所知,可以将command用作Buttons的参数。那么为什么显示此错误
答案 0 :(得分:1)
检查缩进和语法是否在整个shouButtons
函数中。
for循环中的代码块必须缩进。在Button
参数text
和command
之间也缺少逗号。
def showButtons():
for i in players:
btn = Button(window, text=i, command=onclick)
btn.pack(side=LEFT)