File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ from tkinter import Frame , Label , Button
2+
3+
4+ class Timer (Frame ):
5+ def __init__ (self ):
6+ super ().__init__ ()
7+ self .inicio = self .agora = 15
8+ self .pendente = None # alarme pendente
9+ self .grid ()
10+ self .mostrador = Label (
11+ self , width = 2 , anchor = 'e' , font = 'Helvetica 120 bold' )
12+ self .mostrador .grid (column = 0 , row = 0 , sticky = 'nswe' )
13+ self .bt_start = Button (self , text = 'Start' , command = self .start )
14+ self .bt_start .grid (column = 0 , row = 1 , sticky = 'we' )
15+ self .atualizar_mostrador ()
16+
17+ def atualizar_mostrador (self ):
18+ self .mostrador ['text' ] = str (self .agora )
19+
20+ def start (self ):
21+ if self .pendente :
22+ self .after_cancel (self .pendente )
23+ self .agora = self .inicio
24+ self .atualizar_mostrador ()
25+ self .pendente = self .after (1000 , self .tictac )
26+
27+ def tictac (self ):
28+ self .agora -= 1
29+ self .atualizar_mostrador ()
30+ if self .agora > 0 :
31+ self .pendente = self .after (1000 , self .tictac )
32+
33+
34+ if __name__ == '__main__' :
35+ timer = Timer ()
36+ timer .mainloop ()
You can’t perform that action at this time.
0 commit comments