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()我得到错误命令无效语法,但据我所知可以使用命令作为按钮的参数。那么为什么它会显示这个错误
1 回答
守候你守候我
TA贡献1802条经验 获得超10个赞
检查整个shouButtons函数中的缩进和语法。
for 循环中的代码块必须缩进。Button参数text和之间也缺少逗号command。
def showButtons():
for i in players:
btn = Button(window, text=i, command=onclick)
btn.pack(side=LEFT)
添加回答
举报
0/150
提交
取消
