--------- Mensaje reenviado --------
> De: craf <p...@vtr.net>
> Para: Python Tkinter Ingles <tkinter-discuss@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@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.



_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to