[Tutor] Tkinter question

Michael P. Reilly arcege@speakeasy.net
Fri, 2 Nov 2001 17:56:05 -0500


On Fri, Nov 02, 2001 at 04:52:12PM -0500, Chris Scott wrote:
> frame = Frame(root, width=200, height=200)
> frame.bind("<Return>", testPrint)
> frame.pack()
> 
> root.mainloop()
> 
> It's pretty much the same as the one printed, except I've swapped the
> <Button-1> reference for a <Return> reference (have tried with and without
> <>) but I don't get any output in the window when I press the return key. It
> worked with the mouse button. Am I just typing it in wrong? The
> documentation isn't very helpful to me. I appreciate any help, thanks.

The key to remember is that the mouse and the keyboard are two different
input device and that the windowing system doesn't always assume that
both will go to the same window, at the same time.

You need to change the keyboard focus to the new window.  Before you
run the mainloop, also call the focus() method.

frame.bind("<Return>", testPrint)
frame.focus()  # change keyboard input to this window
frame.pack()

root.mainloop() # frame.mainloop() would also work - why?

Good luck.
  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |
| Ailment info: http://www.speakeasy.org/~arcege/michaelwatch.html     |