.pdf、.doc和.docx的内容未显示在我的tkinter文本框中
我正在尝试读取文本文件、pdf文件和ms word文件的内容。我正在为我的GUI使用tkinter。下面显示了我的代码行.pdf、.doc和.docx的内容未显示在我的tkinter文本框中,tkinter,python-3.6,Tkinter,Python 3.6,我正在尝试读取文本文件、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 = ((
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数据 所以我想我必须先把.pdf、.doc和.docx转换成文本?@thereal90:是的。