In this video we’ll create a URL Link shortener using Tkinter and Python.

You’ve seen url shorteners before, creating them is very easy using the URL shortening API wrapper Python library pyshorteners.

In this video we’ll install pyshorteners, and use it to create a simple link shortener with Tkinter!

Python Code: shorty.py
(Github Code)

from tkinter import *
import pyshorteners

root = Tk()
root.title('Codemy.com - Link Shortener')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("500x500")

def shorten():
	if shorty.get():
		shorty.delete(0, END)

	if my_entry.get():
		# Convert to tinyurl
		url = pyshorteners.Shortener().tinyurl.short(my_entry.get())
		# Output to screen
		shorty.insert(END, url)

		# Reverse URL
		print(pyshorteners.Shortener().tinyurl.expand(url))


my_label = Label(root, text="Enter Link To Shorten", font=("Helvetica", 34))
my_label.pack(pady=20)

my_entry = Entry(root, font=("Helvetica", 24))
my_entry.pack(pady=20)

my_button = Button(root, text="Shorten Link", command=shorten, font=("Helvetica", 24))
my_button.pack(pady=20)

shorty_label = Label(root, text="Shortened Link", font=("Helvetica", 14))
shorty_label.pack(pady=50)

shorty = Entry(root, font=("Helvetica", 22), justify=CENTER, width=30, bd=0, bg="systembuttonface")
shorty.pack(pady=10)


root.mainloop()

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of...