0

Lets say this is my code:

from tkinter import *
window = Tk()

entry = Entry(window)
entry.pack()
window.mainloop()

When user types polish letters he then gets weird symbols such a ¹œæ. How to fix that? When I use e.insert(END, "ąść") I see normal polish letters.

martineau
  • 119,623
  • 25
  • 170
  • 301
www987
  • 31
  • 3

1 Answers1

-1

The issue might have occurred because the encoding is set to UTF-8 and not UTF-16. (Refer to the thread What is Unicode, UTF-8, UTF-16?)

Quick Fix: Use u'required_string' instead of 'required_string'.

Rectified Code:

from tkinter import *
window = Tk()

entry = Entry(window)
entry.pack()
entry.insert(END, u"ąść")
window.mainloop()

Output:

Output showing the required polish letters being displayed

Nimantha
  • 6,405
  • 6
  • 28
  • 69
  • 1
    I don't think you understood the question — it's about the _user_ typing character into an on-screen `Entry` widget, not inserting them via the `insert()` method. – martineau Jan 23 '21 at 00:54
  • Also, in Python 3, which this question is definitely using (the module is named `Tkinter` on Python 2), there is *zero* difference between `u"ąść"` and `"ąść"`; the `u` prefix switched from `str` (bytes-like) to `unicode` on Py2, but on Py3, `str` is roughly equivalent to Py2 `unicode`; they both handle Unicode text. – ShadowRanger Jan 23 '21 at 01:04