I would like to make a script or a small program which gives me my cps (clicks per second) but I find a small problem to make a timer of 10 seconds and at the same time click on the button left click. I tried the module threading but it does not work with tkinter I have try everything (make the timer inside the function execute several functions to increment the timer in a variable ex ...) but I never manage to do it at the same time. My program should look like what can makes this site: www.mcrpg.com/kohi-click-test
Ps: to test my problem click on starting not test Start.
import time
import os
from tkinter import *
from tkinter.constants import *
from threading import Thread
class Interface(Frame):
def run(self):
thread1 = Thread(target = self.Démarrer )
thread2 = Thread(target = self.timer)
thread1.start()
thread2.start()
thread1.join()
thread2.join()
fenetre.update()
def timer(self):
length = 10
for i in range(1,(length+1)):
print(i)
self.Label2["text"] = "Le temps est {}".format(i)
fenetre.update()
time.sleep(1)
def MaApp(self):
self.nb_clic += 1
self.cps = (self.nb_clic / 10)
self.Label["text"]="Le Nombre de clic est de {}".format(self.nb_clic)
self.Label1["text"] = "Votre cps est de {}".format(self.cps)
fenetre.update()
def Démarrer(self):
self.bouton_cliquer["text"]= "Clic Gauche"
self.bouton_cliquer["command"] = self.MaApp
fenetre.update()
def __init__(self, fenetre, **kwargs):
Frame.__init__(self, fenetre, **kwargs)
self.pack(fill=BOTH)
fenetre.geometry("400x200+300+300")
fenetre.title("ClickTest")
#Variable
self.nb_clic = 0
self.cps = (self.nb_clic / 10)
self.temps = 0
# Création de nos widgets
self.Label = Label(self , text="Le Nombre de clic est de {}".format(self.nb_clic))
self.Label.pack()
self.Label1 = Label(self, text="Votre cps est de {}".format(self.cps))
self.Label1.pack()
self.Label2 = Label(self , text=("Le temps est {}").format(self.temps))
self.Label2.pack()
self.bouton_quitter = Button(self, text="Quitter",
command=self.quit
)
self.bouton_quitter.pack(side="left")
self.bouton_cliquer = Button(self, text="Démarrer" ,
command=self.run
)
self.bouton_cliquer.pack(side="right")
fenetre.update()
# Bouton de Test
self.bouton_cliquer2 = Button(self, text="Test Démarrer",
command = self.Démarrer
)
self.bouton_cliquer2.pack()
self.bouton_cliquer3 = Button(self, text="Test MaApp",
command = self.MaApp
)
self.bouton_cliquer3.pack()
self.bouton_cliquer4 = Button(self, text="Test Timer",
command = self.timer
)
self.bouton_cliquer4.pack()
if __name__ == '__main__':
fenetre = Tk()
interface = Interface(fenetre)
interface.mainloop()
interface.destroy()