Tk Listbox bindings (was: Tk Listbox Question)

Hans Nowak ivnowa at hvision.nl
Thu Dec 9 17:20:04 EST 1999


On 9 Dec 99, Kevin Cazabon wrote:

> It's actually pretty simple... most of what you need can be found in
> Fred's "Introduction to Tkinter" at:
> http://www.pythonware.com/library/tkinter/introduction
> 
> Here's a quickie though.  It's in a class wrapper because I've build
> myself a 'standard' set of compound widgits that I use.  You could call
> this by simply calling:  "list = display_list(parent, items_in_list)"
> 
> 
> #######################################################################
> class display_list(Frame):
>
> [snip]
>
>         #Here's the bindings
> 
>         self.listbox.bind('<Double-Button-1>', self.do_this)
>         self.listbox.bind('<Control-Button-1>', self.do_that)
>         self.listbox.bind('<Button-2>', self.do_something_else)

While it's easy to bind mouse events to a listbox, I haven't managed 
to bind keyboard events to it. In a current project I have a listbox 
and I want my users to be able to scroll through it using common keys 
like <Up> and <Down>. However, binding them to the listbox, as done 
above, does not work; I don't know why.

If I do a bind_all, it does work, though. Unfortunately, this is not 
the right way to do it; I have another window with a ScrolledText 
widget, and if I scroll there, the listbox scrolls too, due to the 
bind_all effect! 

Experimenting, I also tried binding "<Down>" (etc) to all widgets in 
the current frame, which doesn't work either.

So my obvious question is, how can I bind keyboard events to a 
listbox without having to use bind_all? 

TIA,

--Hans Nowak (zephyrfalcon at hvision.nl)
Homepage: http://fly.to/zephyrfalcon
You call me a masterless man. You are wrong. I am my own master.




More information about the Python-list mailing list