我正在制作一个测验型程序,在其中添加了一个奖励问题,该问题不同于其他问题。在这里,您将获得8个按钮,问题是:
使用给定选项中的四个按钮来弹出列表“ lst”中的所有元素
按钮为:
["lst","while","for","i",":","lst.pop()","in","range(lst)"]
我想做的是单击后禁用每个按钮,单击4次后并禁用所有按钮。
我还想知道,如何检查点击顺序是否正确?
我创建了一个禁用带有索引“ index”的按钮的功能
def disable(buttons,index,word):
buttons[index].config(state="disabled")
然后我在一个循环上创建了8个按钮。
words=["lst","range(lst)"]
buttons = []
for index in range(8):
n = words[index]
button = Button(root,text = n,command = lambda index = index,n = n: disable(buttons,n)).pack(side = 'left')
buttons.append(button)
这是显示的错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py",line 1705,in __call__
return self.func(*args)
File "<ipython-input-163-f56fc3dd64da>",line 340,in <lambda>
button = Button(root,n)).pack(side = 'left')
File "<ipython-input-163-f56fc3dd64da>",line 353,in disable
buttons[index].config(state="disabled")
AttributeError: 'NoneType' object has no attribute 'config'