1
+ import tkinter as tk
2
+ from tkinter import ttk
3
+ import pyshorteners
4
+ import webbrowser
5
+ import tkinter .messagebox as messagebox
6
+ import tkinter .scrolledtext as scrolledtext
7
+ import clipboard
8
+
9
+ BACKGROUND_COLOR = "#000000"
10
+ FOREGROUND_COLOR = "#00FF00"
11
+ BUTTON_COLOR = "#008000"
12
+ ENTRY_COLOR = "#FFFFFF"
13
+
14
+ def shorten_url ():
15
+ long_url = entry .get ()
16
+ s = pyshorteners .Shortener ()
17
+ short_url = s .tinyurl .short (long_url )
18
+ output_label .configure (text = "Short URL:" , foreground = FOREGROUND_COLOR )
19
+ hyperlink_label .configure (text = short_url , foreground = FOREGROUND_COLOR , cursor = "hand2" )
20
+ hyperlink_label .bind ("<Button-1>" , lambda e : webbrowser .open (short_url ))
21
+ copy_button .configure (state = "normal" , command = lambda : copy_to_clipboard (short_url ))
22
+
23
+ def copy_to_clipboard (text ):
24
+ clipboard .copy (text )
25
+ messagebox .showinfo ("gURL Shortener" , "Short URL copied to clipboard." )
26
+
27
+ # Create the main window
28
+ window = tk .Tk ()
29
+ window .title ("gURL Shortener" )
30
+ window .configure (bg = BACKGROUND_COLOR )
31
+ window .geometry ("400x200" )
32
+ window .resizable (False , False )
33
+
34
+ # Style the title bar
35
+ style = ttk .Style ()
36
+ style .theme_use ("clam" )
37
+ style .configure ("TLabel" , foreground = FOREGROUND_COLOR , background = BACKGROUND_COLOR )
38
+ style .configure ("TFrame" , background = BACKGROUND_COLOR )
39
+ style .configure ("TButton" , foreground = FOREGROUND_COLOR , background = BUTTON_COLOR )
40
+ style .configure ("TEntry" , fieldbackground = ENTRY_COLOR )
41
+
42
+ # Create the input label and entry field
43
+ input_label = ttk .Label (window , text = "Enter URL:" )
44
+ input_label .pack ()
45
+ entry = ttk .Entry (window )
46
+ entry .pack ()
47
+
48
+ # Create the "Shorten" button
49
+ button = ttk .Button (window , text = "Shorten" , command = shorten_url )
50
+ button .pack ()
51
+
52
+ # Create the output label and hyperlink label
53
+ output_label = ttk .Label (window , text = "Short URL:" )
54
+ output_label .pack ()
55
+ hyperlink_label = ttk .Label (window , text = "" , cursor = "hand2" )
56
+ hyperlink_label .pack ()
57
+
58
+ # Create the copy button
59
+ copy_button = ttk .Button (window , text = "Copy" , state = "disabled" )
60
+ copy_button .pack ()
61
+
62
+ # Set the window size
63
+ window .geometry ("300x150" )
64
+
65
+ # Start the main event loop
66
+ window .mainloop ()
0 commit comments