Tkinter listbox clicking problem

Matthew Bonig mbonig at hotmail.com
Sat Sep 14 04:28:53 EDT 2002


I'm confused... I looked at these examples but I didn't see anything pop out
that answered my question... or was this mostly for the other post?

Thanks
Matthew Bonig


"Cameron Laird" <claird at starbase.neosoft.com> wrote in message
news:2D7E3697CF5D1521.5D9711540E657ED8.7EF0451C598438FC at lp.airnews.net...
> In article <altfrk$1eva$1 at nntp6.u.washington.edu>,
> Russell E. Owen <owen at nospam.invalid> wrote:
> >In article <sGog9.307183$aA.53945 at sccrnsc02>,
> > "Matthew Bonig" <mbonig at hotmail.com> wrote:
> >
> >>Right now I have it bound so when a Tkinter listbox gets a <Button-1>
> >>(lb.bind("<Button-1>", someFunc)) it calls function someFunc. Now,
> >>someFunc() simply prints the curselection(). The problem is it's
lagged...
> >>if I first select list item 1 (index 0), and then 2, and then 3 (array
> >>indexes 0,1,2) it prints out themout incorrectly.
> >>(I have someFunc actually do some try, except stuff so I don't get
uncaught
> >>exceptions) Instead of printing 0,1,2 it prints "nothing selected", 0,
1.
> >>The function get's called before the listbox updates it's selection
markers!
> >>
> >>Does anybody know how I could force listbox to update it's selection
markers
> >>so instead of printing "nothing selected, 0,1  it prints 0,1,2 like it
> >>should?
> >
> >I'm hoping somebody has better ideas, but here are some to try:
> >
> >Call update_idletasks before you ask for the selection. I have no idea
> >if this will work, but it might.
> >
> >An ugly solution that would probably work:
> >- extract the y coordinate from the event callback
> >- call nearest(y_coord) to get the item closest to the mouse click
> >- explicitly select that index item. You could try skipping this step,
> >but you risk a possible error between what you think they clicked on and
> >what is hightlighted. Unfortunately, this step will may be a real pain
> >for a list that supports multiple selected items.
> >
> >Poll for selection changes -- thus it may take a bit of time before your
> >code notices a change, but it will always be right once it gets there.
> >
> >-- Russell
>
> Whoa!  There's a far easier solution.  Read up on 'bindtags'
> in <URL: http://web.pydoc.org/2.2/Tkinter.html > and elsewhere.
> <URL: http://www.cwi.nl/~jacob/textui.py.html > has a small
> example that almost is pertinent.
> --
>
> Cameron Laird <Cameron at Lairds.com>
> Business:  http://www.Phaseit.net
> Personal:  http://phaseit.net/claird/home.html





More information about the Python-list mailing list