你能告诉我为什么我的命令中出现错误消息无效的语法吗

时间:2019-02-15 12:40:56

标签: python

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的参数。那么为什么显示此错误

1 个答案:

答案 0 :(得分:1)

检查缩进和语法是否在整个shouButtons函数中。

for循环中的代码块必须缩进。在Button参数textcommand之间也缺少逗号。

def showButtons():
     for i in players:
         btn = Button(window, text=i, command=onclick)
         btn.pack(side=LEFT)