two questions on tkinter

Michele Simionato mis6 at pitt.edu
Thu Aug 22 14:40:53 EDT 2002


Hans Nowak <wurmy at earthlink.net> wrote in message news:<3D642FEE.2060005 at earthlink.net>...
> Michele Simionato wrote:
> > I have a couple of questions on Tkinter.
> > 
> > 1. First, how do I bind special keys like #,$,>,<,;0123456789 etc ? How
> > do I bind Space key ? Are the Windows keys recognized ?
> 
> See:
> 
> http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm
> 
> Not sure about the Windows keys.
> 
> > 2. How do I use colors in the Text widget ? For instance I would like to
> > write RED GREEN BLUE with RED in red, GREEN in green and BLUE in blue.
> 
> See:
> 
> http://www.pythonware.com/library/tkinter/introduction/widget-styling.htm#AEN403
> 
> :-)
> 
> HTH,


The effebot's introduction to Tkinter in
http://www.pythonware.com/library/tkinter/introduction/ 
is admittedly useful, well done and FREE. Nevertheless, 
it is by no means complete. I am asking here things which 
are NOT in the guide or that are explained very fast, 
without examples. The links you provided me do not answer
my questions. Anyway, for what concerns the first question 
(Tkinter non-obvious keybindings) I have found the answer 
myself. I discovered that the key symbols are the same as 
in X Windows: for instance '#' is numbersign and can binded as

widget.bind('<numbersign>',dosomething())

'!' is exclam, etc. In my system the complete list of 
keysymbols is in the file /usr/X11R6/include/X11/keysymdef.h .
The Windows keys can be bind as Super_L and Super_R but they
do not work as modifiers, just as simple keys. For
instance the bindings

widget.bind('<Super_L>',dosomething())
widget.bind('<Shift-Super_L>',dosomething())
widget.bind('<Control-Super_L>',dosomething())

are correct, but you cannot do 

widget.bind('<Super_L-a>',dosomething())

There is an inconsistency with numerical keys 
12345 (67890 apparently work fine). Consider for instance
5. You can bind it as

widget.bind('5',dosomething()) #no brackets <>

but

widget.bind('<Control-5>',dosomething())

will not work. I more or less sure this is related
to the shortcuts for mouse bindings, even I would
have expected only 123 to be related to the mouse.
Moreover one cannot bind the numerical keys with
the Shift modifier.

This I discovered by trials and error on my Linux box,
I dunno about Windows. Maybe somebody could be interested
in the (incomplete) list of modifiers, therefore I post
the relevant subsections of keysymdef.h .

For what concerns my second question (an example with
an explanation of how to use colors in the text widget)
I am still waiting an answer.

-- 
Michele Simionato - Dept. of Physics and Astronomy
210 Allen Hall Pittsburgh PA 15260 U.S.A.
Phone: 001-412-624-9041 Fax: 001-412-624-9163
Home-page: http://www.phyast.pitt.edu/~micheles/


*************** Snippet from keysymdef.h *******************

/* Modifiers */

#define XK_Shift_L		0xFFE1	/* Left shift */
#define XK_Shift_R		0xFFE2	/* Right shift */
#define XK_Control_L		0xFFE3	/* Left control */
#define XK_Control_R		0xFFE4	/* Right control */
#define XK_Caps_Lock		0xFFE5	/* Caps lock */
#define XK_Shift_Lock		0xFFE6	/* Shift lock */

#define XK_Meta_L		0xFFE7	/* Left meta */
#define XK_Meta_R		0xFFE8	/* Right meta */
#define XK_Alt_L		0xFFE9	/* Left alt */
#define XK_Alt_R		0xFFEA	/* Right alt */
#define XK_Super_L		0xFFEB	/* Left super */
#define XK_Super_R		0xFFEC	/* Right super */
#define XK_Hyper_L		0xFFED	/* Left hyper */
#define XK_Hyper_R		0xFFEE	/* Right hyper */
#endif /* XK_MISCELLANY */

/*
 *  Latin 1
 *  Byte 3 = 0
 */
#ifdef XK_LATIN1
#define XK_space               0x020
#define XK_exclam              0x021
#define XK_quotedbl            0x022
#define XK_numbersign          0x023
#define XK_dollar              0x024
#define XK_percent             0x025
#define XK_ampersand           0x026
#define XK_apostrophe          0x027
#define XK_quoteright          0x027	/* deprecated */
#define XK_parenleft           0x028
#define XK_parenright          0x029
#define XK_asterisk            0x02a
#define XK_plus                0x02b
#define XK_comma               0x02c
#define XK_minus               0x02d
#define XK_period              0x02e
#define XK_slash               0x02f
#define XK_0                   0x030
#define XK_1                   0x031
#define XK_2                   0x032
#define XK_3                   0x033
#define XK_4                   0x034
#define XK_5                   0x035
#define XK_6                   0x036
#define XK_7                   0x037
#define XK_8                   0x038
#define XK_9                   0x039
#define XK_colon               0x03a
#define XK_semicolon           0x03b
#define XK_less                0x03c
#define XK_equal               0x03d
#define XK_greater             0x03e
#define XK_question            0x03f
#define XK_at                  0x040
#define XK_A                   0x041
#define XK_B                   0x042
#define XK_C                   0x043
#define XK_D                   0x044
#define XK_E                   0x045
#define XK_F                   0x046
#define XK_G                   0x047
#define XK_H                   0x048
#define XK_I                   0x049
#define XK_J                   0x04a
#define XK_K                   0x04b
#define XK_L                   0x04c
#define XK_M                   0x04d
#define XK_N                   0x04e
#define XK_O                   0x04f
#define XK_P                   0x050
#define XK_Q                   0x051
#define XK_R                   0x052
#define XK_S                   0x053
#define XK_T                   0x054
#define XK_U                   0x055
#define XK_V                   0x056
#define XK_W                   0x057
#define XK_X                   0x058
#define XK_Y                   0x059
#define XK_Z                   0x05a
#define XK_bracketleft         0x05b
#define XK_backslash           0x05c
#define XK_bracketright        0x05d
#define XK_asciicircum         0x05e
#define XK_underscore          0x05f
#define XK_grave               0x060
#define XK_quoteleft           0x060	/* deprecated */
#define XK_a                   0x061
#define XK_b                   0x062
#define XK_c                   0x063
#define XK_d                   0x064
#define XK_e                   0x065
#define XK_f                   0x066
#define XK_g                   0x067
#define XK_h                   0x068
#define XK_i                   0x069
#define XK_j                   0x06a
#define XK_k                   0x06b
#define XK_l                   0x06c
#define XK_m                   0x06d
#define XK_n                   0x06e
#define XK_o                   0x06f
#define XK_p                   0x070
#define XK_q                   0x071
#define XK_r                   0x072
#define XK_s                   0x073
#define XK_t                   0x074
#define XK_u                   0x075
#define XK_v                   0x076
#define XK_w                   0x077
#define XK_x                   0x078
#define XK_y                   0x079
#define XK_z                   0x07a
#define XK_braceleft           0x07b
#define XK_bar                 0x07c
#define XK_braceright          0x07d
#define XK_asciitilde          0x07e



More information about the Python-list mailing list