Events and the Listbox widget

Martin Franklin martin.franklin at bedford.waii.com
Thu Oct 5 07:13:30 EDT 2000


I forgot to say it also has a getcurselection() method which seems to 
take care of your problem

Martin Franklin wrote:
> 
> The Pmw.ScrolledListBox has a selectioncommand This specifies a function
> to call when mouse button 1 is single clicked over an entry in the
> listbox
> component.
> 
> HTH
> Martin
> 
> Hans Kristian Ruud wrote:
> >
> > >
> > > >>> Hans Kristian Ruud <hans.kristian.ruud at inenco.no> 10/03/00 09:27AM >>>
> > > I have generated a listbox, and wish to extract some information when a
> > > user
> > >   clicks on an item:
> > >
> > >           list = Listbox(canvas,width=15 )
> > >           list.pack(side=TOP)
> > >           list.bind('<ButtonPress>', chooseSheet)
> > >
> > >           def chooseSheet(event):
> > >                   listbox = event.widget
> > >                   selected = listbox.curselection()
> > >                   setCurSheet( selected[0] )
> > >
> > >   My problem is that the list of selected values from
> > > listbox.curselection()
> > >   is not updated until after chooseSheet is called, i.e. the function
> > >
> > >   listbox.curselection()
> > >
> > >   returns the PREVIOUS element that was clicked.
> > >
> > >   Originally I had bound the function to root, and then it worked fine,
> > > however
> > >   I do not want the function chooseSheet to be executed when I click on
> > > buttons
> > >   and such that I have added later.
> > >
> > >   Any ideas?
> > >   Thanks in advance
> >
> > >
> > > Jake Baker wrote:
> > >
> > >> Use list.bind('<<ListboxSelect>>') instead.
> > >>
> > >
> > > This would of course be the ideal solution; however this feature was only
> > > implemented in
> > > Tcl/Tk 8.3.?, whereas Python 1.5.2 comes with Tcl/Tk 8.0. Upgrading to
> > > Python 1.6 is
> > > not an option, as the win32com package is not available for Python 1.6
> > >
> >
> > This is the solution that I arrived at:
> >
> > list   = Listbox(canvas, width=15 )
> > list.bind('<ButtonPress>', self.chooseSheet)
> > .
> > .
> >
> >  def chooseSheet(event):
> >     listbox = event.widget
> >     selection = listbox.nearest(event.y)
> >     setCurSheet( selection )
> >
> > --
> > Hans Kristian
> >
> > --
> > http://www.python.org/mailman/listinfo/python-list
> 
> --
> http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list