Skip to content

Instantly share code, notes, and snippets.

@gavintranquilino
Created February 26, 2024 16:35
Show Gist options
  • Save gavintranquilino/63962d6711e8b0ab412d16d66feb0301 to your computer and use it in GitHub Desktop.
Save gavintranquilino/63962d6711e8b0ab412d16d66feb0301 to your computer and use it in GitHub Desktop.
Click Speed Test with Python Tkinter
import time
import threading
from tkinter import *
cps = 0
count = 0
def cps_button_active():
global count
count += 1
counter_var.set(count)
if count == 1:
t.start()
def timer():
time.sleep(10)
cps_button["state"] = "disabled"
result_label = Label(root, text=f"Your result is {count/10} clicks per second.")
result_label.place(rely=0.6, relx=0.5, anchor="n")
t = threading.Thread(target=timer)
root = Tk()
root.title("Python click speed test")
window = Canvas(root, height=600, width=800)
window.pack()
counter_var = IntVar()
counter = Label(root, textvariable=counter_var, font=("Courier 10 Pitch", "16", "bold"))
counter.place(rely=0.7, relx=0.5, anchor="n")
cps_button = Button(
root,
text="click here",
bd=3,
bg="lightgray",
activebackground="gray",
activeforeground="white",
command=cps_button_active,
font=("Courier 10 Pitch", "36", "bold"),
)
cps_button.place(relx=0.5, rely=0.3, relwidth=0.5, relheight=0.35, anchor="n")
label = Label(
text="Clicks Per Second", bg="lightblue", font=("Helvetica", "36", "bold")
)
label.place(relx=0.5, anchor="n")
if __name__ == "__main__":
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment