This is the same as http://code.activestate.com/recipes/286155/ For newest version see that page. ---- This module provides two standard TkInter widgets, Entry and ScrolledText, modified for text editing with key bindings that allow entering accented letters, umlauts, etc. Usage: To enter an accented character, press Ctrl-, then press the character key. Example: to enter a with acute, press Ctrl-', A. Accent bindings are defined in the Diacritical.accent table. They should be pretty intuitional. Ctrl-= (equals sign) is used for tilde (~) because the tilde key is somewhat stubborn on Windows keyboards. Not all accents exist on all letters. This is handled by gracefully falling back to the base letter. No bindings for Icelandic eth & thorn, Swedish a-ring, nor German scharfes-s are available at the moment. Additionally, some Tk key bindings are corrected on Windows platform to comply with the standard practice: Ctrl-A is now select-all. {{{ #!python from Tkinter import * from ScrolledText import ScrolledText from unicodedata import lookup import os class Diacritical: """Mix-in class that adds keyboard bindings for accented characters, plus other common functionality.""" if os.name == "nt": stroke = '/' else: stroke = 'minus' accents = (('acute', "'"), ('grave', '`'), ('circumflex', '^'), ('tilde', '='), ('diaeresis', '"'), ('cedilla', ','), ('stroke', stroke)) def __init__(self): # Fix some non-Windows bindings if os.name == 'nt': self.bind("", self.select_all) self.bind("", lambda event: "break") # Diacritical bindings for a, k in self.accents: self.bind("" % k, lambda event, a=a: self.insert_accented(event.char, a)) def insert_accented(self, c, accent): if c.isalpha(): if c.isupper(): cap = 'capital' else: cap = 'small' try: c = lookup("latin %s letter %c with %s" % (cap, c, accent)) self.insert(INSERT, c) return "break" except KeyError, e: pass class DiacriticalEntry(Entry, Diacritical): """Tkinter Entry widget with some extra key bindings for entering typical Unicode characters - with umlauts, accents, etc.""" def __init__(self, master=None, **kwargs): Entry.__init__(self, master=None, **kwargs) Diacritical.__init__(self) def select_all(self, event=None): self.selection_range(0, END) return "break" class DiacriticalText(ScrolledText, Diacritical): """Tkinter ScrolledText widget with some extra key bindings for entering typical Unicode characters - with umlauts, accents, etc.""" def __init__(self, master=None, **kwargs): ScrolledText.__init__(self, master=None, **kwargs) Diacritical.__init__(self) def select_all(self, event=None): self.tag_add(SEL, "1.0", "end-1c") self.mark_set(INSERT, "1.0") self.see(INSERT) return "break" def test(): frame = Frame() frame.pack(fill=BOTH, expand=YES) if os.name == "nt": frame.option_add("*font", "Tahoma 8") # Win default, Tk uses other # The editors entry = DiacriticalEntry(frame) entry.pack(fill=BOTH, expand=YES) text = DiacriticalText(frame, width=76, height=25, wrap=WORD) if os.name == "nt": text.config(font="Arial 10") text.pack(fill=BOTH, expand=YES) text.focus() frame.master.title("Diacritical Editor") frame.mainloop() if __name__ == "__main__": test() }}}