-
Notifications
You must be signed in to change notification settings - Fork 1
/
clock.py
35 lines (29 loc) · 880 Bytes
/
clock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import tkinter as tk
from time import time
class Stopwatch:
def __init__(self, timeElapsed, paused, window, button):
self.timeElapsed = timeElapsed
self.window = window
self.paused = paused
self.button = button
def start(self):
window.mainloop()
toggle()
run_timer()
def toggle(self):
if self.paused:
self.paused = False
self.button.config(text='Stop')
self.oldtime = time()
self.run_timer()
else:
self.paused = True
self.oldtime = time()
self.button.config(text='Start')
def run_timer(self):
if self.paused:
return
delta = int(time() - self.oldtime)
timestr = '{:02}:{:02}'.format(*divmod(delta, 60))
self.timeElapsed.config(text=timestr)
self.timeElapsed.after(1000, self.run_timer)