1

I encounter a problem when trying to bind an umlaut-key (äöü) to a Tkinter window in Python 3.

The error message Tkinter prints out is basically:

Traceback (most recent call last):
    self.tk.bind("Ä", self.take_white_ippon)
_tkinter.TclError: bad ASCII character 0x84

You can try this MCVE:

from tkinter import *
tk = Tk()
def doSomething(e=None):
    print("doSomething()")
# The next line is basically ignored
tk.bind("ä", doSomething)
# This line will throw the error message
tk.bind("<ä>", doSomething)
tk.mainloop()

You can try Alt+0228 to enter an ä (using the number pad).

I have not found any other SO/Google pages about this topic. I have only found some questions about general problems with Tkinter and non-ascii characters.

1 Answer 1

2

Here is a program that can help you:

import tkinter as tk

root = tk.Tk()
tk.Label(text="you pushed:").pack()
var = tk.StringVar()
tk.Entry(textvariable=var).pack()
root.bind('<Key>', lambda e: var.set(repr(e.keysym)))
root.mainloop()

If you run that and type ä, you will see 'adiaeresis', which is what you need to bind:

tk.bind('<adiaeresis>', doSomething)
Sign up to request clarification or add additional context in comments.

2 Comments

Hello, thanks for your answer. But you need to add < and > around adiaeresis to make it work: <adiaeresis>.
I don't think that's the right format for binding. It should be <Key-adiaeresis>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.