[Tkinter-discuss] calling function by keypress

Ilknur Ozturk Ilknur.Ozturk at cabot.com.tr
Mon May 15 14:01:58 CEST 2006


Hi all,

 

I am trying to call my function by keypress. Some specific keys will be
assigned to some buttons. All widgets are created in a class. I wrote
the code as below:

 

    functionalkeys=("Left", "F1",...)

 

    def assignkey(self, event):

        if event.keysym not in self.functionalkeys:

            return

        self.callcommand(event.keysym)

        

   

    def callcommand(self, arg1):

        if arg1=="Left":

            self.writecommand('left')

 

        if arg1=="F1":

            self.writecommand('menu')

 

         ..........

        else:

            return 

 

and bind assignkey() to my buttons,

 

        self.menu=Button(...)

        self.menu.bind("<KeyPress>", self.assignkey)

 

this is working if I focused on the button, otherwise no action. I also
bind keypress event to my main frame, but it is also not working. I am
new for learning tk and most probably I am doing some basic thing wrong
but I could not find it:-( Is there anyone to tell me how can I call the
function without focusing the related button?

 

Thanks....

 

 

 



**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060515/11e4a21d/attachment.htm 


More information about the Tkinter-discuss mailing list