Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 319fe87

Browse files
Merge pull request avinashkranjan#1608 from Abhishek-Rajput-81/master
[GSSOC'23] To add code for Measuring Internet Speed
2 parents dc6b373 + c63d22d commit 319fe87

File tree

3 files changed

+92
-17
lines changed

3 files changed

+92
-17
lines changed

‎Internet-Speed-Test/Internet-Speed-Test.md‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎Internet-Speed-Test/README.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Internet Speed Test
2+
This is a Python program that measures your internet speed using the Speedtest library and displays the results in a graphical user interface (GUI) built with tkinter.
3+
4+
## Prerequisites
5+
Make sure you have the following prerequisites installed:
6+
- speedtest-cli library
7+
- tkinter library (usually comes pre-installed with Python)
8+
9+
## Installation
10+
1. Clone or download the repository to your local machine.
11+
12+
2. Install the required libraries by running the following command:
13+
```
14+
pip install speedtest-cli
15+
```
16+
17+
3. Run the script:
18+
```
19+
python internet_speed_test.py
20+
```
21+
22+
## How to Use
23+
1. After running the script, a GUI window will open.
24+
2. Click the "Run Speed Test" button to initiate the speed test.
25+
3. The program will measure your download speed, upload speed, ping latency, and server information, and display the results in the GUI window.
26+
27+
## Customization
28+
- You can change the primary and secondary color of the GUI by modifying the PRIMARY_COLOR and SECONDARY_COLOR variables in the code.
29+
- If you prefer a different theme for the GUI, you can change it by modifying the style.theme_use() line. Currently, the "clam" theme is used.

‎Internet-Speed-Test/main.py‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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"
8+
9+
speed = Speedtest()
10+
def measure_internet_speed():
11+
print("Running speed test...")
12+
13+
14+
download_speed = speed.download()
15+
# To Convert to Mbps
16+
download_speed = download_speed / 1024 / 1024
17+
print(f"Download Speed: {download_speed:.2f} Mbps")
18+
download_label.config(text=f"Download Speed: {download_speed:.2f} Mbps")
19+
20+
upload_speed = speed.upload()
21+
# To Convert to Mbps
22+
upload_speed = upload_speed / 1024 / 1024
23+
print(f"Upload Speed: {upload_speed:.2f} Mbps")
24+
upload_label.config(text=f"Upload Speed: {upload_speed:.2f} Mbps")
25+
26+
ping_latency = speed.results.ping
27+
print(f"Ping latency: {ping_latency:.2f} ms")
28+
ping_label.config(text=f"Latency: {ping_latency:.2f} ms")
29+
30+
server = speed.get_best_server()
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)
62+
63+
window.mainloop()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /