Skip to content

Commit

Permalink
Adicionado exemplo do Timer
Browse files Browse the repository at this point in the history
Isso fica de acordo com link nos slides do curso
  • Loading branch information
renzon committed Apr 11, 2017
1 parent 38412fd commit 79ef354
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Empty file added exemplos/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions exemplos/timer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from tkinter import Frame, Label, Button


class Timer(Frame):
def __init__(self):
super().__init__()
self.inicio = self.agora = 15
self.pendente = None # alarme pendente
self.grid()
self.mostrador = Label(
self, width=2, anchor='e', font='Helvetica 120 bold')
self.mostrador.grid(column=0, row=0, sticky='nswe')
self.bt_start = Button(self, text='Start', command=self.start)
self.bt_start.grid(column=0, row=1, sticky='we')
self.atualizar_mostrador()

def atualizar_mostrador(self):
self.mostrador['text'] = str(self.agora)

def start(self):
if self.pendente:
self.after_cancel(self.pendente)
self.agora = self.inicio
self.atualizar_mostrador()
self.pendente = self.after(1000, self.tictac)

def tictac(self):
self.agora -= 1
self.atualizar_mostrador()
if self.agora > 0:
self.pendente = self.after(1000, self.tictac)


if __name__ == '__main__':
timer = Timer()
timer.mainloop()

0 comments on commit 79ef354

Please sign in to comment.