from tkinter import *
from tempo import Tempo
class App:
def __init__(self, root=None):
"""Costruttore"""
self.crono=Tempo()
self.radice=root
self.btnStart=Button(self.radice, text=" Avvio ", command=self.BtnstartClick)
self.labTempo=Label(self.radice, text=str(self.crono))
self.btnStop=Button(self.radice, text='Ferma', command=self.btnstopClick)
self.boxIntertempi=Label(self.radice, text='Intertempi:')
self.btnIntertempo=Button(self.radice, text='Intertempo', command=self.btnIntertempoClick)
self.btnRiparti=Button(self.radice, text='Riparti', command=self.btnRipartiClick)
self.labTempo.grid(column=0, row=0)
self.btnStart.grid(column=0, row=1)
self.btnRiparti.grid(column=1, row=1)
self.btnStop.grid(column=2, row=1)
self.btnIntertempo.grid(column=3, row=1)
self.boxIntertempi.grid(column=0, row=2)
self.radice.title('Cronometro')
def aggiornaTempo(self):
"""Aggiorna il tempo"""
if self.crono.attivo:
self.labTempo["text"]=(str(self.crono))
self.radice.after(100, self.aggiornaTempo)
def BtnstartClick(self):
"""Evento pressione comando"""
if self.crono.attivo:
self.boxIntertempi["text"]="%s\n%s ripartenza" %(self.boxIntertempi["text"], str(self.crono))
self.crono.avvia()
self.aggiornaTempo()
def btnstopClick(self):
"""Arresta il cronometraggio"""
if self.crono.attivo:
self.boxIntertempi["text"]="%s\n%s arresto" %(self.boxIntertempi["text"], self.labTempo["text"])
self.crono.ferma()
def btnIntertempoClick(self):
"""Intertempo"""
if self.crono.attivo:
self.boxIntertempi["text"]+="\n%s intertempo" %str(self.crono)
def btnRipartiClick(self):
"""Ripartenza"""
if not self.crono.attivo:
self.crono.riavvia()
self.aggiornaTempo()