[Tkinter-discuss] Tkinter and Alt bindings

Russell Adams RLAdams at AdamsInfoServ.Com
Thu Feb 9 21:51:49 CET 2012


On Thu, Feb 09, 2012 at 09:04:31PM +0100, Michael Lange wrote:
> now I am getting confused ;)

Welcome to the club. ;]

> When I run the above example (or the one by the OP) and press Alt-s,
> nothing is inserted in the entry, and that is just what I would expect
> as of the widget's default bindings, or am I missing something here?

That was my original expectation, I'm trying to solve why the
implementation does not match.

> The default bindings are defined in entry.tcl, the relevant part looks
> like:
>
>   # Ignore all Alt, Meta, and Control keypresses unless explicitly bound.
>   # Otherwise, if a widget binding for one of these is defined, the
>   # <KeyPress> class binding will also fire and insert the character,
>   # which is wrong.  Ditto for Escape, Return, and Tab.
>
>   bind Entry <Alt-KeyPress> {# nothing}

I see these comments, however they don't exclude Mod1, just alt and
other modifiers.

>
> Now, when I comment out the above line and run the examples, the "s" is
> actually inserted in the entry. Russell, is it possible that you miss
> entry.tcl or that it is somehow broken? This would explain why the "s"
> is inserted when Mod1 is used - but unfortunately not why Alt is not
> working  :(

See below.

> I still suspect the WM...   ;)

I don't believe it's the WM. Awesome is minimal unlike something like
KDE or GNOME. I don't control keyboard mappings from it, only xmodmap.

So here's a rundown.

If I reset my keyboard mappings using setxkbmap, my xmodmap looks
like:

$ xmodmap
xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock
control     Control_L (0x25),  Control_L (0x42),  Control_R (0x69)
mod1        Alt_L (0x40),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

My .Xmodmap:

$ cat .Xmodmap
keycode 108 = Alt_R Meta_R ISO_Level3_Shift
add mod4 = Alt_R

After applying:

$ xmodmap
xmodmap:  up to 5 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock
control     Control_L (0x25),  Control_L (0x42),  Control_R (0x69)
mod1        Alt_L (0x40),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3
mod4        Alt_R (0x6c),  Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

I just tested this TCL snippet, and when I reset it works, when I use
the xmodmap for making Alt_R mod4 it doesn't work. How odd, so digging deeper.

The following is from xev:

Reset, pressing just s:

KeyPress event, serial 25, synthetic NO, window 0x3400001,
    root 0xac, subw 0x0, time 51186823, (561,583), root:(650,603),
    state 0x0, keycode 39 (keysym 0x73, s), same_screen YES,
    XLookupString gives 1 bytes: (73) "s"
    XmbLookupString gives 1 bytes: (73) "s"
    XFilterEvent returns: False

After xmodmap, pressing s:

KeyPress event, serial 28, synthetic NO, window 0x3400001,
    root 0xac, subw 0x0, time 51276203, (609,741), root:(698,761),
    state 0x0, keycode 39 (keysym 0x73, s), same_screen YES,
    XLookupString gives 1 bytes: (73) "s"
    XmbLookupString gives 1 bytes: (73) "s"
    XFilterEvent returns: False

Reset, pressing Alt-s:

KeyPress event, serial 28, synthetic NO, window 0x3400001,
    root 0xac, subw 0x0, time 51190045, (561,583), root:(650,603),
    state 0x8, keycode 39 (keysym 0x73, s), same_screen YES,
    XLookupString gives 1 bytes: (73) "s"
    XmbLookupString gives 1 bytes: (73) "s"
    XFilterEvent returns: False

After xmodmap, pressing Alt-s:

KeyPress event, serial 28, synthetic NO, window 0x3400001,
    root 0xac, subw 0x0, time 51277296, (609,741), root:(698,761),
    state 0x8, keycode 39 (keysym 0x73, s), same_screen YES,
    XLookupString gives 1 bytes: (73) "s"
    XmbLookupString gives 1 bytes: (73) "s"
    XFilterEvent returns: False

The xev data is identical, whether I'm using my xmodmap or not. The Tk
behavior *IS* different, without xmodmap Alt works, and with it only
Mod1 is honored.

Getting closer to an answer, but still trying to explain the
behavior.

Does this mean that when Alt_R is bound to anything, the Alt_L
behavior changes? Any why only for Tk?

Thanks.

------------------------------------------------------------------
Russell Adams                            RLAdams at AdamsInfoServ.com

PGP Key ID:     0x1160DCB3           http://www.adamsinfoserv.com/

Fingerprint:    1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3


More information about the Tkinter-discuss mailing list