守株待兔
2011-08-17 09:06:28 UTC
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)
frame.pack()
root.mainloop()
------------------ ???? ------------------
???: "Firat Ozgul"<ozgulfirat at gmail.com>;
????: 2011?8?17?(???) ??1:46
???: "????"<1248283536 at qq.com>;
??: Re: [Tkinter-discuss] bind between event and callback
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]
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20110817/b8c2ac40/attachment.html>
from Tkinter import *
root = Tk()
def callback(event):
print "i am here"
frame = Frame(root, width=100, height=100)
frame.bind("<Button-1>", callback)
frame.pack()
root.mainloop()
------------------ ???? ------------------
???: "Firat Ozgul"<ozgulfirat at gmail.com>;
????: 2011?8?17?(???) ??1:46
???: "????"<1248283536 at qq.com>;
??: Re: [Tkinter-discuss] bind between event and callback
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]
code1
from Tkinter import *
root = Tk()
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()
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
Tkinter-discuss at python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
-------------- next part --------------from Tkinter import *
root = Tk()
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()
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
Tkinter-discuss at python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20110817/b8c2ac40/attachment.html>