Welcome Coders,
In This Tutorial We are Going to make a internet speed detector application using python tkinter module.
Before Getting Started Lets take a quick view of all the modules that are required for making this application.
Output:
Check The Output Below
Module Used:
- tkinter
- Io Module
- Urllib.request
- Pil
- time
- subprocess
- threading
- re
- speed test cli
Installation
To Install pillow
pip install pillow #Image Processing Library
To Install Speed Cli
pip install speedtest-cli #For Speed Checking
Source Code
from io import BytesIO
from tkinter import *
from urllib.request import urlopen
from PIL import Image,ImageTk
import time,subprocess,threading
import re
root = Tk()
root.title("Speed Cheker By Coder Community")
file=r"F:\12.gif"
canvas=Canvas(root,width=386,height=100)
canvas.pack()
# DISPLAYING IT ON BANNER
Banner=ImageTk.PhotoImage(Image.open("F:banner.jpg"))
canvas.create_image(0,0,image=Banner,anchor=NW )
window=Frame(root,width=300,height=300)
window.pack()
info = Image.open(file)
frames = info.n_frames #Frames of Gif
# creating list of each frame
im = [PhotoImage(file=file,format=f"gif -index {i}") for i in range(frames)]
count = 0
main1=Frame(root)
canvas1=Canvas(root,width=400,height=200,bg="grey")
prog=Text(main1,height=10,width=52,bg="black",fg="green",font=("Arial bold",10))
prog.grid(row=0,column=0)
scrollbar=Scrollbar(main1)
scrollbar.grid(row=0,column=1,sticky=NE+SE)
scrollbar.config(command=prog.yview)
#main animation od gif
def animation(count):
start.pack_forget()
label1.grid(row=0,column=0)
label2.grid(row=2,column=0)
global anim
im2 = im[count]
gif_label.configure(image=im2)
count += 1
if count == frames:
count = 0
root.after(5,lambda :animation(count))
return
#FOr Checking Speed
def main():
global image1
returned_text = subprocess.check_output("speedtest-cli --share", shell=True, universal_newlines=True)
print(returned_text)
url=re.search("(?P <url>https?://[^\s]+)", returned_text).group("url")
window.pack_forget()
main1.pack()
canvas1.pack()
prog.insert(END,returned_text)
u=urlopen(url).read()
im=Image.open(BytesIO(u))
resize=im.resize((400,200), Image.ANTIALIAS)
image1=ImageTk.PhotoImage(resize)
canvas1.create_image(0,0,image=image1,anchor=NW)
def thread1():
thread=threading.Thread(target=animation(count))
thread.start()
def thread2():
thread=threading.Thread(target=main)
thread.start()
gif_label = Label(window,image="")
gif_label.grid(row=1,column=0)
start = Button(root,text="Check Internet Speed",font=("Arial bold",15),bg="lightblue",command= lambda :[thread1(),thread2()],borderwidth=7)
start.pack(fill=BOTH,ipady=20)
label1=Label(window,text="Checking Speed Please Wait.....",font=("Arial bold",12))
label2=Label(window,text="This Might Take Few Seconds..",font=("Arial bold",12))
root.mainloop()
Download Source Code File:
Download Material Used In This Application:
0 Comments