Home > database >  Some letters cannot be detected while typing in tkinter's input widgets
Some letters cannot be detected while typing in tkinter's input widgets

Time:12-14

Apparently some letters can't be typed in Tk's input widgets such as Tk.Text, Tk.Entry.

When I try to type some Turkish letters, they can't be detected. But when I first type in Notepad then copy paste into the widgets or by using the insert attribute, it somehow works. I tried various font families but same result. What causes this and is there any way to fix this?

root = Tk()

entry = Entry(root, width=60, font=('Comic Sans MS', 15))
entry.pack(pady=50, padx=50)
entry.insert("1", "şşşşşŞŞŞŞŞııııığğğğğĞĞĞĞĞİİİİİ")

textbox = Text(root, font=('Comic Sans MS', 10))
textbox.pack(pady=50, padx=50)
textbox.insert("1.0", "şşşşş\nŞŞŞŞŞ\nııııı\nğğğğğ\nĞĞĞĞĞ\nİİİİİ")

root.mainloop()

enter image description here

CodePudding user response:

I solved it by writing a real-time letter replacing function.

def replace_chars(self):
    input_word = entry.get()
    final_ver = input_word
    for i, l in enumerate(input_word):
        try:
            subst_letter = l.encode(encoding="iso8859_10").decode(encoding="iso8859_9")
            final_ver = final_ver[:i]   subst_letter   final_ver[i 1:]
        except:
            continue
    entry.delete(0, END)
    entry.insert(0, final_ver)
entry = Entry(root)
entry.pack()
entry.bind('<KeyRelease>', replace_chars)
  • Related