[Tkinter-discuss] Pressing buttons

Bob Greschke bob at passcal.nmt.edu
Wed Apr 4 23:05:22 CEST 2007


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
>>



More information about the Tkinter-discuss mailing list