[Tutor] Tab key in tkinter

Jim jf_byrnes at comcast.net
Thu Oct 24 09:48:30 EDT 2019


On 10/24/19 7:25 AM, Alan G wrote:
> I am guessing but it is probably similar to the function keys _did you try them
> with your code? Look at the event driven programming page in my tutor to see how
> I dealt with those, something similar should be possible.
> 
> Alan g

Just tried the function keys. F1-F9 produces keycodes 67-75. F10 shows 
nothing. F11-F12 shows 95-96. Even stranger. Will look at your page 
later today.

Thanks,  Jim

> On 24 Oct 2019 03:20, Jim <jf_byrnes at comcast.net> wrote:
> 
>      I needed to know the keycodes for the tab and return keys. When I was
>      searching for them I came across this little program. I modified it to
>      give me the keycodes. It seems to work with every key I tried except the
>      tab key. I wonder why? The tab key does work in my editor.
> 
>      # bind and show a key press event with Tkinter
>      # tested with Python24      vegaseat     20nov2006
>      from tkinter import *
>      root = Tk()
>      prompt = '      Press any key      '
>      label1 = Label(root, text=prompt, width=len(prompt), bg='yellow')
>      label1.pack()
>      def key(event):
>            if event.char == event.keysym:
>                msg = 'Normal Key %r' % event.keycode #event.char
>            elif len(event.char) == 1:
>                msg = 'Punctuation Key %r (%r)' % (event.keycode, event.char)
>         #(event.keysym, event.char)
>                # added by me
>                if event.keycode == 23:
>                    print('tab')
>                else:
>                    print('nada')
>            else:
>                msg = 'Special Key %r' % event.keycode #event.keysym
>                # added by me
>                if event.keycode == 23:
>                    print('tab')
>                else:
>                    print('nada')
>            label1.config(text=msg)
>      root.bind_all('<Key>', key)
>      root.mainloop()
> 
>      Thanks,  Jim
> 
>      _______________________________________________
>      Tutor maillist  -  Tutor at python.org
>      To unsubscribe or change subscription options:
>      https://mail.python.org/mailman/listinfo/tutor
> 
> 



More information about the Tutor mailing list