The Shift-BackSpace bug

There is a bug you may notice while typing into a Tkinter.Entry, Tkinter.Text or some other widget where you can type, but it is known to happen only under Linux. The problem is that pressing "Shift-BackSpace" does not necessarily do what one would expect, instead of removing the previous character it inserts a ^B or '\b' or a rectangle (bad character).

Solving it

At least it is solvable, but it does not involve Tk or the Tkinter wrapper at all. The first thing to do is to find out what key is Tk actually getting when you press Shift-BackSpace, to do that use the following code:

   1 import Tkinter
   2 
   3 def show_key(event):
   4     print event.keysym, event.keycode, hex(event.keysym_num)
   5 
   6 root = Tkinter.Tk()
   7 root.bind("<Key>", show_key)
   8 
   9 root.mainloop()
  10 

Run it and press Shift-BackSpace, it will probably show something like this:

Shift_L 50 0xffe1
Terminate_Server 22 0xfed5

Notice how Shift-BackSpace is assigned to something else here, Terminate_Server (although it doesn't terminate my X session when I press this key combination). To confirm it, do this:

$ xmodmap -pk | grep 0xfed5

     22         0xff08 (BackSpace)      0xfed5 (Terminate_Server)       0xff08
(BackSpace)     0xfed5 (Terminate_Server)       0xff08 (BackSpace)      0xfed5
(Terminate_Server)

The second keysym in this output indicates that when I press the key 22 (BackSpace) while holding shift, a Terminate_Server is sent. For more information about the output consult the xmodmap documentation.

Then, to fix the initial problem you can do the following:

$ xmodmap -e "keycode 22 = BackSpace"

But then it may happen that you can no longer issue a Ctrl-Alt-BackSpace to finalize your X (till you end this session and start another, since nothing was permanently saved here). Apparently this is caused by a conflict between xkb and xmodmap.

tkinter: Linux%Shift-Backspace (last edited 2010-07-26 11:59:11 by localhost)