[Tkinter-discuss] how to hit enter and get the Entry() text

Alexnb alexnbryan at gmail.com
Tue Jun 10 17:19:11 CEST 2008




Guilherme Polo wrote:
> 
> On Tue, Jun 10, 2008 at 1:59 AM, Alexnb <alexnbryan at gmail.com> wrote:
>>
>> Okay, so I am new to Tkinter, and can't figure out how to get the text
>> out of
>> my Entry() text box. I know I can make a button or something like that
>> where
>> they click it and I get it. But what I want to do is have the user typing
>> in
>> the box, and then they hit "return" or "enter" and that also gets it for
>> example:
>>
> 
> You have to bind <Return> to your entry widget.
> 
>> [code]
>>
>> e = Entry(root, width=25)
>> e.pack()
>>
>> Button1 = Button(root, command=get)
>> Button1.pack()
>>
>> def get():
>>    print e.get()
>>
>> [/code]
>>
> 
> I'm sure you have defined this function "get" before that point since
> that code would fail.
> 
>> Something like that, only I want to eliminate the button, and make it to
>> where the user hits enter in the text box and it does the get() function.
>> Help?
> 
> def get(event):
>     print event.widget.get()
> 
> e = Entry(root, width=25)
> e.bind('<Return>', get)
> e.pack()
> 
>> --
>> View this message in context:
>> http://www.nabble.com/how-to-hit-enter-and-get-the-Entry%28%29-text-tp17747813p17747813.html
>> Sent from the Python - tkinter-discuss mailing list archive at
>> Nabble.com.
>>
>> _______________________________________________
>> Tkinter-discuss mailing list
>> Tkinter-discuss at python.org
>> http://mail.python.org/mailman/listinfo/tkinter-discuss
>>
> 
> 
> 
> -- 
> -- Guilherme H. Polo Goncalves
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
> 
> 


It worked, but I thought I already tried that.. I guess I had done it wrong
or something. Thanks alot!

-- 
View this message in context: http://www.nabble.com/how-to-hit-enter-and-get-the-Entry%28%29-text-tp17747813p17757997.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.



More information about the Tkinter-discuss mailing list