尝试在列表框中未选择索引而不是在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
谢谢你的帮助!在
根据错误,
i
的值不是“active、anchor、end、@x、y或数字”。在找出
i
的值和类型,然后确保它是要获取的有效参数。另外,即使它看起来像一个数字,也要确保它是int
而不是str
类型。如果它是字符串,则先将其转换为int。在相关问题 更多 >
编程相关推荐