[Tkinter-discuss] Pressing buttons
Michael Lange
klappnase at web.de
Wed Apr 4 11:31:25 CEST 2007
On Wed, 04 Apr 2007 13:26:35 +1000
John McMonagle <jmcmonagle at 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
More information about the Tkinter-discuss
mailing list