def getwh(event):
wh=room.whname.get(room.whname.curselection())
room.cNewRoM['text']=wh
return wh
if getwh(1) in ['东墙(门窗)','西墙(门窗)','南墙(门窗)','北墙(门窗)']:
Qmc=(gettn(1)-int(tw)*int(Fmc)*geta(0)*Kmc) #Q1=(tn-tw)*F*a*K
报错如下:
wh=room.whname.get(room.whname.curselection())
File "C:\Users\AI\Anaconda3\lib\tkinter\__init__.py", line 2798, in get
return self.tk.call(self._w, 'get', first)
TclError: bad listbox index "": must be active, anchor, end, @x,y, or a number
请问各位大佬问题出在哪了?
我的解决方案:
绑定事件是:<ButtonRelease-1>
绑定方法获取选中值使用:
event.widget.get(event.widget.curselection())
list_box_config = Listbox(self.frame, selectmode=SINGLE)
list_box_config.bind('<ButtonRelease-1>', select_config)
def select_config(event):
print(event.widget.get(event.widget.curselection()))
thanks http://www.itkeyword.com/doc/1715070224370926222/python-tkinter-listbox-event-binding