Answer the question
In order to leave comments, you need to log in
Problem with python encoding: files + tkinter, how to fix?
I am writing a small graphical application using python 3 + tkinter. In this piece of code
file = open("testfile.txt", 'r')
t = file.read()
label = Label(root, text=t, font="Arial 14")
label.pack(side="top")
file.close()
Answer the question
In order to leave comments, you need to log in
https://docs.python.org/3/library/functions.html#open
Try explicitly specifying the encoding of text a in this file.
Like this:
f = open("myfile.txt", "r", encoding="utf-8")
Or like this:
f = open("myfile.txt", "r", encoding="cp866")
Set the encoding parameter of the open function to the encoding of the file being opened.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question