[Tkinter-discuss] [Fwd: Problems with hotkeys]
craf
prog at vtr.net
Sat Jan 8 02:25:06 CET 2011
--------- Mensaje reenviado --------
> De: craf <prog at vtr.net>
> Para: Python Tkinter Ingles <tkinter-discuss at python.org>
> Asunto: [Tkinter-discuss] Problems with hotkeys
> Fecha: Fri, 07 Jan 2011 20:18:05 -0300
>
> 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
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
Hi.
I answer:
modify this:
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))
for this:
self.root.bind('<Alt_L><o>', lambda e, widget=self:one(widget))
self.root.bind('<Alt_L><t>', lambda e, widget=self:two(widget))
self.root.bind('<Alt_L><h>', lambda e, widget=self:three(widget))
Regards.
Cristian Abarzúa F.
More information about the Tkinter-discuss
mailing list