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 file and copy paste the following code



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")
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():
    file_url = url.get()
    file_name_aft_click = filename.get()
    if".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"):
            m_box.showinfo("Download Compleated","Your File Successfully Downloaded")
            m_box.showerror("Error","File Name Already Exist in Downloading Path !")
        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)


See also  Python 3 Tkinter Validating or Limiting Entry in Numerical Textbox Widget GUI Desktop App Full Project For Beginners


Now if you execute the python application by typing below command












Leave a Reply