How to insert arabic script into Tkinter text widget correctly? How to insert arabic script into Tkinter text widget correctly? tkinter tkinter

How to insert arabic script into Tkinter text widget correctly?


As you answered in the comment, the TEXT is already escaped. Change the function that generate the TEXT to correctly return a string.

If you can't control the function that generate the text, unescape the text using str.decode with unicode_escape encoding.

>>> TEXT = u'word=\\u0631\\u064e\\u062c\\u0627'>>> print TEXTword=\u0631\u064e\u062c\u0627>>> TEXT = TEXT.decode('unicode-escape')>>> print TEXTword=رَجا

Example

# coding: utf-8from Tkinter import *root = Tk()text = Text(root)text.pack()QUERY = u'\u0627\u0631\u062c\u0648'TEXT = u'word=\\u0631\\u064e\\u062c\\u0627'  # escaped!!TEXT = TEXT.decode('unicode-escape')word = re.findall(u'word=.*', TEXT, re.UNICODE)[0]header = " ".join([QUERY, word])text.insert('1.0', "".join([header,'\n']))root.mainloop()

enter image description here