|
List Info
Thread: Pressing buttons
|
|
| Pressing buttons |
  Spain |
2007-04-03 05:51:01 |
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 python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
a>
|
|
| Re: Pressing buttons |
  United States |
2007-04-03 21:49:17 |
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 fitbak.com>
To: <tkinter-discuss 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 python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
a>
>
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
a>
|
|
| Re: Pressing buttons |

|
2007-04-03 22:26:35 |
Bob Greschke wrote:
> 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
>
Not sure where Bob pulled "variable" out of, but
rest assured it's not
an option to the Entry widget.
Something along these lines may help (note I've excluded the
Button as
it appears to be redundant in this case):
from Tkinter import *
root = Tk()
def onPressEnter(event):
print event.widget.get() # Get entry widget's
string
event.widget.delete(0, END) # Clears the entry
widget
e = Entry(root, width=10)
e.pack()
e.bind('<Return>', onPressEnter)
e.bind('<KP_Enter>', onPressEnter)
root.mainloop()
Regards,
John
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
a>
|
|
| Re: Pressing buttons |
  Germany |
2007-04-04 04:31:25 |
On Wed, 04 Apr 2007 13:26:35 +1000
John McMonagle <jmcmonagle velseis.com.au> wrote:
> Bob Greschke wrote:
> > 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
> >
> Not sure where Bob pulled "variable" out of,
but rest assured it's not
> an option to the Entry widget.
>
<snip>
Bob meant "textvariable" not "variable",
so it must be:
Ent = Entry(Sub, width = 10, textvariable = EntryVar)
Michael
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
a>
|
|
| Re: Pressing buttons |
  United States |
2007-04-04 16:05:22 |
Oops. Yup. I fixed when I cut an pasted from the email and
tried
and run it, but forgot to go back and change the email. The
spelling
checker should check for things like that. It should
be
"textvariable = EntryVar" in the Entry() line.
Bob
On Apr 3, 2007, at 21:26, John McMonagle wrote:
> Not sure where Bob pulled "variable" out of,
but rest assured it's not
> an option to the Entry widget.
> Bob Greschke wrote:
>> 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
>>
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
a>
|
|
[1-5]
|
|