【发布时间】:2020-01-13 15:27:25
【问题描述】:
我正在尝试阅读文本文件、pdf 文件和 ms word 文件的内容。我正在为我的 GUI 使用 tkinter。显示了我的代码行
import tkinter as tk
m = tk.Tk()
e1 = tk.Text(m)
e1.grid(column=0, row=1)
def uploadf():
filename = tk.filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("text file","*.txt"),("pdf file","*.pdf"),("docx file","*.docx"), ("doc file","*.doc"),("all files","*.*")))
filename2 = open(filename, "r")
filen = []
for line in filename2:
filen.append(line)
for x in filen:
e1.insert("end",x)
btn = tk.Button(m, text= "Upload", command= uploadf)
btn.grid(column=1, row=0)
m.mainloop()
我收到此错误 UnicodeDecodeError:“charmap”编解码器无法解码位置 662 中的字节 0x9d:字符映射到 可能是什么问题?
【问题讨论】:
标签: tkinter python-3.6