How can i give input bengali or Unicode languages in tkinter python

Clash Royale CLAN TAG#URR8PPPHow can i give input bengali or Unicode languages in tkinter python
I am beginner in GUI platform in python.I tr to Create a text box , but when i input other language except English specially Bengali it shows ??. Can anyone help me out . I attach my code and sample output
try:
from tkinter import *
import sys
except ImportError:
from tkinter import *
import sys
class App(object):
def __init__(self,parent):
self.frame1 = Frame(parent, highlightbackground="green", highlightcolor="#666D00", highlightthickness=7, width=700, height=700, bd= 10)
self.frame1.pack()
self.frame1.pack_propagate(False)
parent.geometry("700x700")
parent.resizable(0, 0)
self.frame1.configure(background='white')
self.text1 = Label(text="আপনার অনুচ্ছেদ পূরণ করুন (বাংলা):",font=("Lohit Bengali", 16))
self.text1.place(x=110, y=100)
self.T = Text(self.frame1,bd=5)
#self.T.config(font=("helvetica"))
#self.T.insert(END, u'ji'.encode("utf-8"))
self.T.place(x=120, y=150, height=90, width=300)
root = Tk()
root.call('encoding', 'system', 'utf-8')
app = App(root)
root.mainloop()
When i try to input bengali it shows ???
1 Answer
1
there are several aspects here, firstly you should declare your source file encoding:
# -*- coding: utf8 -*-
this must be either the first or second line in the file.
secondly you need to ensure your editor is actually saving in that encoding (easy to do with an editor such as notepad++, without knowing what you're using instructions will vary)
and lastly even though strings in python3 are treated as unicode by default its best to be explicit:
self.text1 = Label(text=u"আপনার অনুচ্ছেদ পূরণ করুন (বাংলা):",font=("Lohit Bengali", 16))
note the added u just before the opening quotes?
u
I tested this on my machine and while my editor (notepad++) doesn't show the characters, the characters are shown on the tkinter window when it is run.
also, your code as pasted has both import sets the same, i.e. if the first fails so will the second, on of the tkinter's should be capitalized.
tkinter
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.