我一直在制作一个骰子游戏,当我把图像分配给每个Tkinter标签以便骰子显示时,我开始得到这个错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1486, in __call__
return self.func(*args)
File "C:/Users/Logan/Desktop/Dice/dicelab2.py", line 56, in rollDice
self.dice[i].roll()
File "C:/Users/Logan/Desktop/Dice/dicelab2.py", line 35, in roll
self.display.config(image=Photolist[self.value-1])
IndexError: list index out of range
现在这个列表有6个条目,我从self调用它。价值观。自我价值应该是1到6之间的随机整数。在我调用它之前,我减去1,这样它应该在Photolist的索引内。还有什么会导致这个错误? 我的代码是:
^{pr2}$
在您的代码中,
Photolist = []
所以您试图访问空列表而不是类中的列表,我将其更改为一个属性,这样您现在应该没有问题了相关问题 更多 >
编程相关推荐