tkinter button widget

Jeff Epler jepler at unpythonic.net
Sat May 15 19:27:20 EDT 2004


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