[Tkinter-discuss] [Fwd: Re: Use underline]
craf
prog at vtr.net
Wed Dec 29 20:27:04 CET 2010
--------- Mensaje reenviado --------
> De: python at bdurham.com
> Para: craf <prog at vtr.net>, Python Tkinter Ingles
> <tkinter-discuss at python.org>
> Asunto: Re: [Tkinter-discuss] Use underline
> Fecha: Wed, 29 Dec 2010 13:52:08 -0500
>
> Cristian,
>
> You have to bind your Alt key presses separately. The underline= only
> underlines the letter - it does not bind to an event handler.
>
> Here's a snippet that may give you some ideas. Disclaimer: I'm not sure
> if its best practice or not.
>
> Malcolm
>
>
> """
> Treat Alt+I as a shortcut keystroke for the Insert button
> """
>
> import Tkinter as tk
> import ttk
>
> def onClick( event=None ):
> if event:
> print event.keysym, event.keysym_num, event.state
>
> # event.state == 131104 regardless of left or right alt
> key
> if event.keysym == 'i' and event.state == 131104:
> pass
> else:
> return
>
> button1.focus_set()
> entry1.delete( 0, 'end' )
> entry1.insert( 'end', '<Open clicked>' )
>
> root = tk.Tk()
>
> style = dict( padx=24, pady=24 )
> entry1 = tk.Entry( root )
> entry1.pack( **style )
> entry2 = tk.Entry( root )
> entry2.pack( **style )
>
> button1 = ttk.Button( root, text='Insert text', underline=0,
> command=onClick )
> button1.pack( **style )
>
> # bind shortcut keystrokes at the outermost container
> root.bind( '<Key>', onClick )
>
> root.mainloop()
Thanks Malcom for the Tips!
Regards.
Cristian Abarzúa F.
More information about the Tkinter-discuss
mailing list