[Tutor] Tkinter and keyboard output

Michael Lange klappnase at freenet.de
Sat Mar 26 01:15:12 CET 2005


On Thu, 24 Mar 2005 18:05:25 -0000
"Igor Riabtchuk" <igor.r at vodafone.net> wrote:

> Hi, 
> 
> I was playing around with Tkinter bindings and I got a question which is probably not particularly bright.
> 
> If I have the following code, it works because I specifically code a function for <Alt-p> keypress:
> 
> from Tkinter import *
> 
> class CRED(Frame):
>     def __init__(self):
>         Frame.__init__(self)
>         self.txt=Text(self)
>         self.txt.bind('<Alt-p>', self.conv)
>         self.txt.pack()
>         self.pack()
>         self.txt.focus()
> 
>     def conv(self,event):
>         self.txt.insert(END,'t')
>         return 'break'
> 
> app=CRED()
> app.mainloop()
> 
> What if instead of coding <Alt-p>, I coded <Alt-Key>  - how would I implement the function which would allow the code to determine which 'Key' was pressed after Alt?
> 
> Thank you.
> Igor

Do you mean something like this:

>>> from Tkinter import *
>>> r=Tk()
>>> t=Text(r)
>>> t.pack()
>>> 
>>> def  test(event):
...     print event.keysym
... 
>>> t.bind('<Alt-Key>', test)
'1077686180test'
>>> x # Alt-x was pressed

?

Michael




More information about the Tutor mailing list