【问题标题】:contents of .pdf, .doc and .docx not displaying in my tkinter text box.pdf、.doc 和 .docx 的内容未显示在我的 tkinter 文本框中
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 所以我想我必须先将 .pdf、.doc 和 .docx 转换为文本?
    • @thereal90:是的。
    猜你喜欢
    • 2016-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-01
    相关资源
    最近更新 更多