Python 3 Tkinter Script to Convert MS Word DOCX to HTML Document Using mammoth Library GUI Desktop Full Project For Beginners

Python 3 Tkinter Script to Convert MS Word DOCX to HTML Document Using mammoth Library GUI Desktop Full Project For Beginners

 

Welcome folks today in this blog post we will be building a ms word docx to html converter using mammoth library in tkinter. All the full source code of application is given below.

 

 

Get Started

 

 

In order to get started you need to install the following library using the pip command as shown below

 

pip install mammoth

 

After installing this library you need to make an app.py file and copy paste the following code

 

app.py

 

# Run python script in same directory as .docx file

import mammoth
import os
import tkinter 
from tkinter.filedialog import askopenfilename

filename = (
    askopenfilename()
)  # show an "Open" dialog box and return the path to the selected file
print(filename)

file = open(filename)

with open(filename, "rb") as docx_file:
    result = mammoth.convert_to_html(docx_file)
    html = result.value  # HTML file generated by mammoth
    messages = result.messages  # Error messages will be stored here

os.getcwd()

f = open("index.html", "w+")  # Opens index.html file, makes new if not present
f.write(html)  # Writes content of variable to file
f.close  # Close file

 

See also  Python 3 PyQt5 Export BarChart Signal to PDF Document Using pyqtgraph & FPDF Library GUI Desktop App Full Project For Beginners

 

Now if you execute the above python script by typing the below command as shown below

 

python app.py

 

Leave a Reply