-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Isso fica de acordo com link nos slides do curso
- Loading branch information
renzon
committed
Apr 11, 2017
1 parent
38412fd
commit 79ef354
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |