Tk: How would I add an accelerator on a button/label in tkinter

morden morden at shadows.net
Mon Jan 13 20:08:02 EST 2003


Say I have this example from Lutz's book:

#!/usr/bin/python

from Tkinter import *
def cb(): print 'Hello'

Button(None, {'text':'pr~ess', 'command':cb, 
Pack:{'side':'left'}}).mainloop()

Button(None, {Pack:{'side':LEFT}}, text='press', command=cb).mainloop()

widget = Button(None, text='pres~s', command=cb)
widget.pack(side=LEFT)
widget.mainloop()

Button(None, text='press', command=cb).pack(side=LEFT)
mainloop()

root = Tk()
Button(root, text='press', command=cb).pack(side=LEFT)
root.mainloop()

# Setting config options...

widget = Button()
widget.config(text='press', command=cb)
widget.pack(side=LEFT)
widget.mainloop()

widget = Button()
widget['text'] = 'press'
widget['command'] = cb
widget.pack(side=LEFT)
widget.mainloop()


How could I make the button pressed when user presses Alt-P
on the keyboard? I saw accelerators on menus in Tk screenshots
found on the web but I haven't seen any on standalone buttons.
Is there any way to get those?





More information about the Python-list mailing list