P o o

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import tkinter as tk

import time

class Chrono:
temps : int
def __init__(self):
self.temps = 0
self.t_zero = time.time()
def __str__(self):
self.__actualiser__()
return str(self.temps) + "s"
def __actualiser__(self):
self.temps = time.time() - self.t_zero

class chronoGUI:
def __init__(self, root):
self.root = root
self.chrono = Chrono()

self.label = tk.Label(root,text="0s",font=("Arial",20))
self.label.pack()

self.Bouton_start = tk.Button(root,text="start",command=self.start_chrono)
self.Bouton_start.pack()
self.Bouton_stop = tk.Button(root,text="stop",command=self.stop_chrono)
self.Bouton_stop.pack()

def start_chrono(self):
self.chrono = Chrono()
self.update_label()
self.root.after(1000,self.update_label)
def stop_chrono(self):
self.root.after_cancel(self.update_label)
def update_label(self):
temps_str =self.chrono.str()
self.label.config(text=str(self.chrono))
self.root.after(1000,self.update_label)

root = tk.Tk()
root.title("Chronomètre")
chrono_gui=chronoGUI(root)

root.mainloop()

You might also like