Python Tkinter GUI Script to Download PDF Document From URL Desktop App Full Project For Beginners

Python Tkinter GUI Script to Download PDF Document From URL Desktop App Full Project For Beginners

 

Welcome folks today in this blog post we will be building a tkinter desktop app in which we will be downloading pdf documents from url. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to install the following libraries using the pip command into your python project

 

pip install tkinter

 

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

 

app.py

 

 

from tkinter import ttk
from tkinter import *
import time
import requests
from tqdm import tqdm
import os
from tkinter import messagebox as m_box
import re

win = Tk()
win.title("PDF Downloader")
win.geometry("500x360")
win.minsize(500,360)
win.maxsize(500,360)
frame = ttk.LabelFrame(win, width=290)
frame.pack(padx=30, pady=90)
label1 = ttk.Label(frame, text="Enter The File URL : ")
label1.grid(row=0, column=0,sticky=W)
url = StringVar()
edit_txt = ttk.Entry(frame, width=50, textvariable=url)
edit_txt.grid(row=1, columnspan=4, padx=2, pady=3)
label2 = ttk.Label(frame, text="Enter The File Name : ")
label2.grid(row=2, column=0,sticky=W)
filename = StringVar()
file_name = ttk.Entry(frame, width=50, textvariable=filename)
file_name.grid(row=3, columnspan=4, padx=2, pady=3)

def onClick():
    os.chdir(r"C:\Users\geeky\Desktop\Projects\qrcode\Tkinter_Screen_Recorder\PDF-Downloader-GUI-Tkinter-Python")
    file_url = url.get()
    file_name_aft_click = filename.get()
    if re.search(".pdf", file_url):
        if (os.path.exists(file_name_aft_click + ".pdf") == False):
            r = requests.get(file_url, stream= True)
            total_size = int(r.headers['content-length'])
            status = Label(win, text="Downloading PDF File...", font="Arial 11", relief=SUNKEN, anchor=W)
            status.pack(side=BOTTOM, fill=X)
            with open(file_name_aft_click + ".pdf", 'wb') as f:
                for data in tqdm(iterable=r.iter_content(chunk_size = 1024), total=total_size/1024, unit="KB"):
                    f.write(data)
            m_box.showinfo("Download Compleated","Your File Successfully Downloaded")
            status.forget()
        else:
            m_box.showerror("Error","File Name Already Exist in Downloading Path !")
    else:
        m_box.showerror("Error", "Only PDF Files are Allowed to Download !")


btn1 = ttk.Button(frame, width=30, text="Download File", command=onClick)
btn1.grid(row=4, columnspan=4, padx=30, pady=5)
win.mainloop()

 

READ  Python 3 PySpark Library Example to Read CSV Files Using Spark Library Full Tutorial For Beginners

 

Now if you execute the python application by typing below command

 

python app.py

 

 

 

 

 

 

 

 

 

Leave a Reply