【发布时间】:2015-08-01 02:01:40
【问题描述】:
我正在尝试创建一个简单的 GUI,允许用户按下按钮,这将从显示的列表框中删除一个条目。但是,如果没有选择条目,控制台会抛出错误,那么我将如何确定用户是否选择了条目。这是我的代码:
selection = self.recipe_list.curselection()
if not selection is None:
self.recipe_list.delete(selection)
else:
print("Nothing to delete!")
【问题讨论】:
-
您遇到的错误是什么?
-
TclError: bad listbox index "": must be active, anchor, end, @x,y, or a number