Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
没有选择的Python列表框_Python_Listbox - Fatal编程技术网

没有选择的Python列表框

没有选择的Python列表框,python,listbox,Python,Listbox,如果列表框中未选择索引,则尝试弹出消息框,而不是在Python中执行该操作 i=Studlistbox.curselection() if i=='': Mbox('Error', 'Nothing has been selected', 0) else: seltext=Studlistbox.get(i) seltext=str(seltext) seltext=seltext.replace(",",'').replace("(","").replace(

如果列表框中未选择索引,则尝试弹出消息框,而不是在Python中执行该操作

 i=Studlistbox.curselection()
if i=='':
    Mbox('Error', 'Nothing has been selected', 0)
else:
    seltext=Studlistbox.get(i)
    seltext=str(seltext)
    seltext=seltext.replace(",",'').replace("(","").replace(")",'').replace("'",'')
    for s in seltext.split(' '):
        if is_number(s):
            seltext=s
....
如果未选择任何项目,则会出现以下错误:

文件“C:\Python33\lib\tkinter\uuuu init\uuuuuu.py”,第2631行,在get中 返回self.tk.call(self._w'get',first) _tkinter.TclError:错误的列表框索引“”:必须是活动的、锚定的、结束的、@x、y或数字


谢谢你的帮助

根据错误,
i
的值不是“活动、锚定、结束、@x、y或数字”


找出
i
的值和类型,然后确保它是要获取的有效参数。而且,即使它看起来像一个数字,也要确保它是
int
而不是
str
类型。如果它是字符串,则首先将其转换为int。

那么i的实际值是多少?我猜它不是“活动、锚定、结束、@x、y或一个数字”,而是列表框中的索引。如果在列表框中选择了某个内容,则一切正常。这就是您所说的
i
,但错误有所不同。你需要亲自检查
i
并确认。它只是试图获取一个空的选择,因为没有选择任何内容。因此,当它需要一个值时,它返回“”。这个问题在这里得到了回答:在哪里措辞更好。