Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 28, 2022 09:46 am GMT

GUI url shortener using python

Here is the Code for GUI Url Shortener using python



from tkinter import *from tkinter import ttkimport pyshorteners # pip install pyshortneresimport webbrowser# main windowroot=Tk()root.title("URL Shortner")root.geometry("500x250")root.resizable(0, 0)# labellabel=ttk.Label(root, text="URL Shortener", font=('Popping', 25))label.grid(row=0)# label for input URLurl_input=ttk.Label(root, text="Enter URL: ")url_input.grid(row=1, column=0, pady=10)# input fied for URLurl=StringVar()url_entry=ttk.Entry(root, textvariable=url, width=40)url_entry.grid(row=1, column=1, pady=10)# Button for Short URLshorten_button=ttk.Button(root, text="Shorten", command= lambda: shorten_url(url.get()))shorten_button.grid(row=2, column=0, pady=10)# label for shortebed Urlshortened_url_label=ttk.Label(root, text="Shortened Url: ")shortened_url_label.grid(row=4, column=0, pady=10)# input field for output Urloutput_url=StringVar()output_url_entry=ttk.Entry(root, textvariable=output_url, width=40)output_url_entry.grid(row=4, column=1, pady=10)# button for Copy Urlcopy_button=ttk.Button(root, text="Copy", command=lambda: copy_url(output_url.get()))copy_button.grid(row=5, column=0, pady=10)# open Buttonopen_button=ttk.Button(root, text="Open", command=lambda: open_url(url.get()))open_button.grid(row=5, column=1, pady=10)# Function to short URLdef shorten_url(url):    try:        short_url=pyshorteners.Shortener().tinyurl.short(url)        output_url.set(short_url)    except:        print("Invalid Url")# function to copy urldef copy_url(url):    try:        url_entry.clipboard_clear()        url_entry.clipboard_append(url)        print("Url Copied to clipboard")    except:        print("invalid URL")# function to open URLdef open_url(url):    try:        webbrowser.open(url)    except:        print("invalid Url")root.mainloop()

Youtube Tutorial

Watch Here




Find Me On:

Facebook
Youtube
Github


Original Link: https://dev.to/technicalvandar885/gui-url-shortener-using-python-2ck8

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To