[Tkinter-discuss] Problems with hotkeys

craf prog at vtr.net
Sat Jan 8 00:18:05 CET 2011


Hi.

I'm trying to use the hotkeys access to controls.

My code is as follows:

---------------------------------------------------------------------
import Tkinter

class App:
    def __init__(self, master):
        self.root = master

        self.entry = Tkinter.Entry(self.root)
        self.entry.pack()
        self.entry.focus_set()

        self.b1 = Tkinter.Button(self.root, text='One', underline=0)
        self.b1.pack()

        self.b2 = Tkinter.Button(self.root, text='Two', underline=0)
        self.b2.pack()

        self.b3 = Tkinter.Button(self.root, text='Three', underline=1)
        self.b3.pack()

        self.b1.bind('<Alt_L><o>', lambda e, widget=self:one(widget))
        self.b2.bind('<Alt_L><t>', lambda e, widget=self:two(widget))
        self.b3.bind('<Alt_L><h>', lambda e, widget=self:three(widget))

def one(widget):
    widget.entry.focus
    widget.root.title('Press Button One')

def two(widget):
    widget.root.title('Press Button Two')

def three(widget):
    widget.root.title('Press Button Three')

master = Tkinter.Tk()
master.geometry('640x480')
app = App(master)
master.mainloop()
--------------------------------------------------------------------

1. The entry control has focus when you open the application.

2. The hotkeys for the buttons work only if they have focus

There is a way of pressing a key combination without the focus this on
the button that has focus at that time?


Thanks and advance.

Regards.

Cristian Abarzúa



More information about the Tkinter-discuss mailing list