Skip to content

Commit 6a1c884

Browse files
Added GUI using tkinter
1 parent de9e192 commit 6a1c884

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

Internet-Speed-Test/main.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,63 @@
1-
21
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"
38

9+
speed = Speedtest()
410
def measure_internet_speed():
5-
speed = Speedtest()
611
print("Running speed test...")
712

13+
814
download_speed = speed.download()
915
# To Convert to Mbps
1016
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")
1219

1320
upload_speed = speed.upload()
1421
# To Convert to Mbps
1522
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")
1725

1826
ping_latency = speed.results.ping
1927
print(f"Ping latency: {ping_latency:.2f} ms")
28+
ping_label.config(text=f"Latency: {ping_latency:.2f} ms")
2029

2130
server = speed.get_best_server()
2231
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)
2362

24-
measure_internet_speed()
63+
window.mainloop()

0 commit comments

Comments
 (0)