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