tkinter button widget

Elaine Jackson elainejackson7355 at home.com
Sat May 15 23:54:43 EDT 2004


Thanks for replying, but what you suggest doesn't seem to be working. Nothing I
try gets the button to have focus in the first place. If I omit the part
corresponding to

e = Tkinter.Entry()
e.pack()
b.pack(anchor=Tkinter.E)

then nothing happens, but if I include it, it's an error. Maybe you can point me
toward some kind of online resource? My favorite would be to get the knowledge
required for this one trick (invoking a button's function with a keypress
instead of a mouse click) without climbing any more of the Tkinter learning
curve (for now) than I need to.

Peace


"Jeff Epler" <jepler at unpythonic.net> wrote in message
news:mailman.0.1084663672.13608.python-list at python.org...
| You'll have to arrange for the widget with keyboard focus to have a
| binding for the "<Return>" event ("<Enter>" is a valid event name, but
| it refers to the event generated when the mouse pointer enters a
| widget).  The called function would call the invoke() method on the
| button.
|
| You can create a binding on all widgets within a given toplevel by
| making the binding on the toplevel itself.
|
| Example:
|
|     import Tkinter
|
|     def c():
|         print "button invoked"
|
|     t = Tkinter.Tk()
|     b = Tkinter.Button(t, text="Do the thing", command=c)
|     t.bind("<Return>", lambda event: b.invoke())
|     e = Tkinter.Entry()
|     e.pack()
|     b.pack(anchor=Tkinter.E)
|     t.mainloop()
|
| Jeff
|





More information about the Python-list mailing list