0
我嘗試使用Tkinter的在文本控件Unicode文件窗口小部件的文字,這是我的代碼寫作Unicode文件在Python
import codecs
def callback():
matric_name = entry.get()
with open(matric_name.rstrip('\n')+".txt", 'r') as content_file:
content = content_file.read()
#myFile=file(matric_name.rstrip('\n')+".txt") # get a file handle
# myText= myFile.read() # read the file to variable
# f = codecs.open(matric_name.rstrip('\n')+".txt", mode="r", encoding="iso-8859-1")
# myText= f.read()
# print myText
# myFile.close()
print content
mytext.insert(0.0,content)
它是否能正確打印,但它不是寫正確地控件文本
控件上的輸出是ÿþS
您的縮進被搞砸了,很難理解 –
@BryanOakley對不起,縮進,現在我改正了 – yagyavrat