-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
125 lines (100 loc) · 4.35 KB
/
main.py
File metadata and controls
125 lines (100 loc) · 4.35 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import customtkinter as ctk
from tkinter import messagebox
from PIL import Image
from customtkinter import CTkImage
import threading
import speedtest
# Global variables
is_dark_mode = True
history = []
def toggle_dark_mode():
global is_dark_mode
is_dark_mode = not is_dark_mode
mode = "dark" if is_dark_mode else "light"
ctk.set_appearance_mode(mode)
dark_mode_btn.configure(text="☀ Light Mode" if is_dark_mode else "🌙 Dark Mode")
def test_speed():
def run_speed_test():
try:
result_textbox.configure(state="normal")
result_textbox.delete("1.0", "end")
result_textbox.insert("end", "🚀 Testing... Please wait.\n", "testing_tag")
result_textbox.tag_config("testing_tag", foreground="#FFA500") # Orange color
result_textbox.configure(state="disabled")
app.update_idletasks()
st = speedtest.Speedtest()
st.get_best_server()
isp = st.results.client["isp"]
server = st.get_best_server()
server_location = f"{server['name']}, {server['country']}"
download_speed = st.download() / 1_000_000
upload_speed = st.upload() / 1_000_000
ping = st.results.ping
result_text = (
f"🌐 ISP: {isp}\n"
f"📍 Server: {server_location}\n"
f"⬇ Download: {download_speed:.2f} Mbps\n"
f"⬆ Upload: {upload_speed:.2f} Mbps\n"
f"⚡ Ping: {ping:.2f} ms"
)
result_textbox.configure(state="normal")
result_textbox.delete("1.0", "end")
result_textbox.insert("end", result_text)
result_textbox.configure(state="disabled")
history.append(result_text)
if len(history) > 10:
history.pop(0)
history_textbox.configure(state="normal")
history_textbox.delete("1.0", "end")
history_textbox.insert("end", "\n\n".join(history))
history_textbox.configure(state="disabled")
except speedtest.ConfigRetrievalError:
messagebox.showerror("Error", "Failed to retrieve Speedtest configuration. Check your internet connection.")
except speedtest.NoMatchedServers:
messagebox.showerror("Error", "No Speedtest servers available. Try again later.")
except Exception as e:
messagebox.showerror("Error", f"Speed test failed: {e}")
threading.Thread(target=run_speed_test, daemon=True).start()
# Initialize customtkinter
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("blue")
# Main Window
app = ctk.CTk()
app.title("Network Speed Test")
app.geometry("1200x780")
app.resizable(False, False)
# Glass Frame
glass_frame = ctk.CTkFrame(app, width=1000, height=700, corner_radius=15)
glass_frame.place(relx=0.5, rely=0.5, anchor="center")
# Speedometer Image
image = Image.open("image.png")
icon_image = CTkImage(dark_image=image, size=(150, 150))
icon_label = ctk.CTkLabel(glass_frame, image=icon_image, text="")
icon_label.pack(pady=10)
# Title
title_label = ctk.CTkLabel(glass_frame, text="🌐 Internet Speed Test", font=("Berlin Sans FB", 26, "bold"))
title_label.pack(pady=10)
# Test Button
start_btn = ctk.CTkButton(glass_frame, text="🚀 Start Test", font=("Berlin Sans FB", 20), command=test_speed)
start_btn.pack(pady=10)
# Dark Mode Toggle
dark_mode_btn = ctk.CTkButton(glass_frame, text="☀ Light Mode", font=("Berlin Sans FB", 20), command=toggle_dark_mode)
dark_mode_btn.pack(pady=10)
# Result Box
result_textbox = ctk.CTkTextbox(glass_frame, font=("Berlin Sans FB", 16), width=850, height=150)
result_textbox.insert("end", "Click the button to test")
result_textbox.configure(state="disabled")
result_textbox.pack(pady=10)
# History Label
history_label = ctk.CTkLabel(glass_frame, text="📜 Test History", font=("Berlin Sans FB", 20, "bold"))
history_label.pack(pady=5)
# History Frame with Scrollbar
history_frame = ctk.CTkFrame(glass_frame, width=900, height=200)
history_frame.pack_propagate(False)
history_frame.pack(pady=5)
history_textbox = ctk.CTkTextbox(history_frame, font=("Berlin Sans FB", 14), wrap="word")
history_textbox.insert("end", "History will appear here.")
history_textbox.configure(state="disabled")
history_textbox.pack(side="left", fill="both", expand=True)
# Run App
app.mainloop()