forked from Tejas1510/Hacking-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathURLShortener.py
More file actions
78 lines (61 loc) · 1.85 KB
/
URLShortener.py
File metadata and controls
78 lines (61 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from tkinter import *
import pyshorteners
import clipboard
window = Tk()
# set deafault window size
window.geometry("350x150") # width x height
# make window not resizable
window.resizable(False, False) # not resizable in x and y
# app title
window.title("URL Shortener")
# swoc logo
p1 = PhotoImage(file='images/swoc-logo.png')
window.iconphoto(False, p1)
# url entry
url_input = Entry(window, font=("TimesNewRoman", "16"))
url_input.grid(row=1, column=2, pady=6)
# label shortened url
str_url = StringVar(window)
shortened_url = Label(window,
textvariable=str_url,
font=("TimesNewRoman", "16"),
fg="#fff",
bg="#1abc9c")
shortened_url.grid(row=3, column=2, pady=6)
# copy short url function
def copy_short_url():
try:
clipboard.copy(str_url.get())
print("Url copied successfully !!")
except:
str_url.set("Something wrong try again !!")
# Copy short url button
copy_btn = Button(window,
text="Copy",
bg="#34495e",
fg="#fff",
font=("TimesNewRoman", "12"),
command=copy_short_url)
copy_btn.grid(row=3, column=3, pady=6, padx=10)
# short url function
def short_url():
try:
s = pyshorteners.Shortener()
url = url_input.get()
final_result = s.tinyurl.short(url)
str_url.set(final_result)
url_input.delete(0, END) # clear input
except:
str_url.set("Enter url please !! ")
# click button to short url
btn = Button(window,
text="Shorten Url",
padx=8,
pady=4,
bg="#2ecc71",
fg="#fff",
font=("TimesNewRoman", "16"),
activebackground="#16a085",
command=short_url)
btn.grid(row=2, column=2, pady=6)
window.mainloop()