“值错误:列表.删除(x) :x不在列表中“

2024-10-04 11:26:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道怎么了,我查了很多线索,还没有得到答案。我的代码基本上是一个更大的程序的一部分,这个程序太大了,无法上传。这是一个tkinter应用程序,当我点击按钮a,然后“def pressa”工作。它工作得很好,但每次在某一点上,我来与这个错误上面,但如果我再次点击按钮,它的工作,直到再次得到一个错误。这是错误:

"Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\ReLoaDeR\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1699, in __call__
    return self.func(*args)
  File "C:\Users\ReLoaDeR\AppData\Local\Programs\Python\Python37\project\project.py", line 31, in pressa
    y=(ap[epilogh])
IndexError: list index out of range"

^{pr2}$

为什么有时候我的代码运行得很好,然后意外地得到了这个错误?在


Tags: inpy程序tkinterlocal错误call按钮
1条回答
网友
1楼 · 发布于 2024-10-04 11:26:17

问题是ap小于er。在

if er!=[] and ap!=[]:
epilogh=random.randint(0, len(er)-1) //Get a number larger than size of ap. 
x=(er[epilogh])
y=(ap[epilogh]) // ap doesnt have that index. 
if x in er:
    er.remove(x)
if y in ap:
    ap.remove(y)
q.set(x)
an.set(y)

{{1>你应该得到另一个随机数。在

相关问题 更多 >