Skip to content

Commit 199f873

Browse files
author
renzon
committed
Adicionado exemplo do Timer
Isso fica de acordo com link nos slides do curso
1 parent eacfc5b commit 199f873

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

exemplos/__init__.py

Whitespace-only changes.

exemplos/timer.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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()

0 commit comments

Comments
 (0)