简体   繁体   中英

Tkinter Text widget sometime doesn't register dead-keys (^ ` ")

I'm making a python program with a gui using Tkinter and its Text widget. I'm using python 2.7.3 and Ubuntu 14.04.

I'm using a "Canadian multilingual" keyboard layout as seen here: http://charsetplus.tripod.com/Keyboard/Latin/ENFR-CAN.htm

When I create the Text widget, everything works fine. Minimum working example:

from Tkinter import *
root=Tk()
text_widget=Text(root)
text_widget.pack()
root.mainloop()

I can then type dead-keys and accented characters with no problem as well as accents with no letter underneath by typing either a dead-key twice, or "dead-key + space"; eg ^ ¨

But if I execute functions in my program or switch to an other program then go back to my text widget, I can't type dead-keys anymore.

My program is math oriented and based on LaTeX, so the circumflex character ^ is pretty much essential.

So far my workaround has been to bind "Control-h" (for hat) on the Text widget to a function that inserts the correct character in the text widget:

self.text_widget.bind('<Control-h',self.circumflex)
# [...]
def circumflex(self,event):
    event.widget.insert(INSERT,'^^')

This works but is annoying, and clearly not elegant.

Any help to resolve this issue would be greatly appreciated!

Thank you!

It seems to be an concurency problem when other input method than XIM is use.

There is a lot of bugs opened about this problem (especialy this one: https://code.google.com/p/ibus/issues/detail?id=526 )

A workaround is to deactivate any other input method before any call to tk:

os.environ['XMODIFIERS'] = "@im=none"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM