-3

I am trying to display a .docx document on my UI. Here's my code:

import tkinter as tk 

class viewers(tk.Frame):
    def __init__(self,master = None):
        from main import a
        document = Document(a)
        super().__init__(master)
        self.master = master
        self.pack()
        T = Text(root,state='normal',height=15,width=60)
        T.pack()
        T.insert(END,open(a).read())
    def create_widgets(self):
        self.quit = tk.Button(self,text="QUIT",fg="red",command=self.master.destroy)
        self.quit.pack(side="top")

1 Answers1

0

You can't display a docx file in tkinter. You'll have to parse the document yourself, and use the features of the text widget (eg: configurable tags) to reproduce the document. It will be unlikely you'll be able to accurately reproduce the formatting, but you can get reasonably close for simple documents that are mostly text.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685