Thus spoketh "守株待兔" <[hidden email]>
unto us on Wed, 17 Aug 2011 17:06:28 +0800:
> why in the following code,there is no "frame.focus_set()" in the
> code ,it can run ,why?? from Tkinter import *
> root = Tk()
> def callback(event):
> print "i am here"
> frame = Frame(root, width=100, height=100)
> frame.bind("<Button-1>", callback)
Mouse events are handled differently than key events.
When you click somewhere in the window of course the window manager
"knows" which widget is clicked - the one under the mouse pointer's "hot
spot". But when you press some key on your keyboard - how would the window
manager "know" which window and which of its child widgets "is meant"?
That is where the "keyboard focus" comes in. Keyboard events are always
sent (by the window manager) to the window that has focus, where
"window" does not only mean a main application window like your Tk()
instannce, but also "child windows" as your Tkinter.Frame() .