.pdf、.doc和.docx的内容未显示在我的 tkinter 文本框中



我正在尝试读取文本文件,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:字符映射到可能是什么问题?

文本小组件只能显示文本,不能显示.pdf、.doc和.docx数据。

最新更新