[Tkinter-discuss] Pressing buttons
Bob Greschke
bob at greschke.com
Wed Apr 4 04:49:17 CEST 2007
You want to do something like this:
from Tkinter import *
Root = Tk()
EntryVar = StringVar()
def doSomething(e = None):
print EntryVar.get()
return
Sub = Frame(Root)
Ent = Entry(Sub, width = 10, variable = EntryVar)
Ent.pack(side = LEFT)
Ent.bind("<Return>", doSomething)
Ent.bind("<KP_Enter>", doSomething) <- for the numeric keypad Enter key
Button(Sub, text = "OK", command = doSomething).pack(side = LEFT)
Sub.pack(side = TOP)
Root.mainloop()
It is important that the Entry field .pack() be on a line by itself and not
combined like Entry().pack(), otherwise Ent will be equal to None and the
bind will not work.
No problem with the English. We'll get through it. :)
Bob
----- Original Message -----
From: "Ekaitz Lizundia" <elizundia at fitbak.com>
To: <tkinter-discuss at python.org>
Sent: Tuesday, April 03, 2007 04:51
Subject: [Tkinter-discuss] Pressing buttons
> Hi,
> how can i do the following it ? I have an Entry and a button "ok". I
> need that with the keyboard put a number and press enter.
>
> i put 456
> press enter
>
> The program must call a function, and later, the position of mouse is in
> entry again.
>
> Sorry, my english is very bad.
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
More information about the Tkinter-discuss
mailing list