[Tutor] Windows 98 Tkinter binding event <Return> fails
Michael P. Reilly
arcege@shore.net
Sun, 26 Nov 2000 09:19:06 -0500 (EST)
>
> I took bind1.py from Fredrik Lundhs Introduction to Tkinter and
> altered it slightly to wait for the Enter key instead of a mouse button
> :
> ---------------------------------------------
> from Tkinter import *
>
> root = Tk ()
>
> def callback ( event ) :
> print 'called the callback!'
>
> frame = Frame ( root, width=100, height=100 )
> frame.bind ( '<Return>', callback )
> frame.pack ()
>
> root.mainloop ()
> ---------------------------------------------
> It does not work. Does that mean that it is impossible to use unbuffered
> keyboard input with Tkinter under Windows ?
Try putting the focus into the frame:
frame.bind ( '<Return>', callback )
frame.pack ()
frame.focus ()
The system needs to know which window (or in this case, which sub-window)
to direct the keystrokes to.
-Arcege
--
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager | Email: arcege@shore.net |
| Salem, Mass. USA 01970 | |
------------------------------------------------------------------------