1
-
2
1
from speedtest import Speedtest
2
+ import tkinter as tk
3
+ from tkinter import ttk
4
+ from ttkthemes import ThemedStyle
5
+
6
+ PRIMARY_COLOR = "#4287f5"
7
+ SECONDARY_COLOR = "#ffffff"
3
8
9
+ speed = Speedtest ()
4
10
def measure_internet_speed ():
5
- speed = Speedtest ()
6
11
print ("Running speed test..." )
7
12
13
+
8
14
download_speed = speed .download ()
9
15
# To Convert to Mbps
10
16
download_speed = download_speed / 1024 / 1024
11
- print (f"Download speed: { download_speed :.2f} Mbps" )
17
+ print (f"Download Speed: { download_speed :.2f} Mbps" )
18
+ download_label .config (text = f"Download Speed: { download_speed :.2f} Mbps" )
12
19
13
20
upload_speed = speed .upload ()
14
21
# To Convert to Mbps
15
22
upload_speed = upload_speed / 1024 / 1024
16
- print (f"Upload speed: { upload_speed :.2f} Mbps" )
23
+ print (f"Upload Speed: { upload_speed :.2f} Mbps" )
24
+ upload_label .config (text = f"Upload Speed: { upload_speed :.2f} Mbps" )
17
25
18
26
ping_latency = speed .results .ping
19
27
print (f"Ping latency: { ping_latency :.2f} ms" )
28
+ ping_label .config (text = f"Latency: { ping_latency :.2f} ms" )
20
29
21
30
server = speed .get_best_server ()
22
31
print (f"Server: { server ['sponsor' ]} ({ server ['name' ]} )" )
32
+ server_label .config (text = f"Server: { server ['sponsor' ]} ({ server ['name' ]} )" )
33
+
34
+
35
+ window = tk .Tk ()
36
+ window .title ("Internet Speed Test" )
37
+ window .geometry ("500x250" )
38
+
39
+
40
+
41
+ style = ThemedStyle (window )
42
+ style .theme_use ('clam' )
43
+ style .configure ("TLabel" , foreground = PRIMARY_COLOR , background = SECONDARY_COLOR )
44
+ style .configure ("TButton" , foreground = SECONDARY_COLOR , background = PRIMARY_COLOR )
45
+
46
+
47
+
48
+ download_label = ttk .Label (window , text = "Download Speed: " , font = ("TkDefaultFont" , 15 , "bold" ))
49
+ download_label .pack (pady = 10 )
50
+
51
+ upload_label = ttk .Label (window , text = "Upload Speed: " , font = ("TkDefaultFont" , 15 , "bold" ))
52
+ upload_label .pack (pady = 10 )
53
+
54
+ ping_label = ttk .Label (window , text = "Latency: " , font = ("TkDefaultFont" , 15 , "bold" ))
55
+ ping_label .pack (pady = 10 )
56
+
57
+ server_label = ttk .Label (window , text = "Server: " , font = ("TkDefaultFont" , 15 , "bold" ))
58
+ server_label .pack (pady = 10 )
59
+
60
+ measure_button = tk .Button (window , text = " Run Speed Test " , command = measure_internet_speed , fg = SECONDARY_COLOR , bg = PRIMARY_COLOR ,font = ("TkDefaultFont" , 12 , "bold" ))
61
+ measure_button .pack (pady = 10 )
23
62
24
- measure_internet_speed ()
63
+ window . mainloop ()
0 commit comments