bind between event and callback

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

bind between event and callback

luofeiyu
code1
from Tkinter import *
root = Tk()
def callback(event):
    print "i am here"
   
frame = Frame(root, width=100, height=100)
frame.bind("<Return>", callback)
frame.pack()
root.mainloop()

when  i press  "enter",there is no output  "i am here"
code2
from Tkinter import *
root = Tk()
def callback(event):
    print "i am here"
   
frame = Frame(root, width=100, height=100)
frame.bind("<Key>", callback)
frame.pack()
root.mainloop()

when  i press  any key ,there is no output  "i am here"

_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: bind between event and callback

Firat Ozgul
The reason why you get no response is the lack of focus when you first
create the frame. Therefore you should set the focus on frame
manually, like this:

[code]
from Tkinter import *
root = Tk()
def callback(event):
   print "i am here"

frame = Frame(root, width=100, height=100)
frame.bind("<Key>", callback)
frame.focus_set()
frame.pack()
root.mainloop()
[/code]

2011/8/17 守株待兔 <[hidden email]>:

> code1
> from Tkinter import *
> root = Tk()
> def callback(event):
>     print "i am here"
>
> frame = Frame(root, width=100, height=100)
> frame.bind("<Return>", callback)
> frame.pack()
> root.mainloop()
>
> when  i press  "enter",there is no output  "i am here"
> code2
> from Tkinter import *
> root = Tk()
> def callback(event):
>     print "i am here"
>
> frame = Frame(root, width=100, height=100)
> frame.bind("<Key>", callback)
> frame.pack()
> root.mainloop()
>
> when  i press  any key ,there is no output  "i am here"
>
> _______________________________________________
> Tkinter-discuss mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
>
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss