Python Tkinter Listbox rightclick event -


i attempting create event such when user right clicks on item in listbox, event can further processing on item.

#define event handler  def myrightclickeventhandler(event):     print "right mouse button pressed"      w = event.widget      print w.curselection()     print      index = int(w.curselection()[0])     value = w.get(index)      print 'you selected item %d: "%s"' % (index, value)     print  #create listbox  my_list_box = tk.listbox(my_frame, selectmode="single") my_list_box.grid()  #bind mouse event  my_list_box.bind("<button-3>", myrightclickeventhandler) 

upon right click, event triggers fine, first time right mouse button clicked, (and subsequent times no intervening left mouse click,) handler fails "tuple index out of range"

if, however, user first left clicks, highlights item, right click works after that.

how can right click both highlight item (i guess makes active,) continues event processing?

program output error message, result of right click no left click first:

right mouse button pressed ()  exception in tkinter callback traceback (most recent call last):     file "c:\python27\lib\lib-tk\tkinter.py", line 1537, in __call__       return self.func(*args)     file "p:\_midframe.py", line 36, in myrightclickeventhandler       index = int(w.curselection()[0]) indexerror: tuple index out of range 

any appreciated.

thanks, mark.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -