没有选择的Python列表框

2024-10-01 04:50:17 发布

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

尝试在列表框中未选择索引而不是在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
....

如果没有选择任何项目,则会出现以下错误:

File "C:\Python33\lib\tkinter__init__.py", line 2631, in get return self.tk.call(self._w, 'get', first) _tkinter.TclError: bad listbox index "": must be active, anchor, end, @x,y, or a number

谢谢你的帮助!在


Tags: inself消息numbergetiftkintererror
1条回答
网友
1楼 · 发布于 2024-10-01 04:50:17

根据错误,i的值不是“active、anchor、end、@x、y或数字”。在

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

相关问题 更多 >