-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCronometro
70 lines (45 loc) · 1.42 KB
/
Cronometro
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#https://py3.codeskulptor.org/#user304_VmgdyOvNRdpTXSo.py
import simplegui
global time, timeString, acerto, tentativa
global rodando
def formato(tempo):
decseg = tempo % 10
seg = (tempo - decseg) / 10 % 60
minu = tempo // 600
return "%.0f:%.0f.%.0f" % (minu, seg, decseg)
def timer_handler():
global time, timeString
time = time + 1
timeString = formato(time)
def draw_handler(canvas):
global timeString, acerto, tentativa
canvas.draw_text("%i/%i" % (acerto, tentativa), [390,30], 30, 'White')
canvas.draw_text(timeString, [150, 100], 40, 'Blue')
def comecar_handler():
global rodando
rodando = True
timer.start()
def parar_handler():
global acerto, tentativa, rodando, time
timer.stop()
if(rodando):
tentativa = tentativa + 1
if(time % 10 == 0):
acerto = acerto + 1
rodando = False
def resetar_handler():
global acerto, tentativa, rodando, time, timeString
timer.stop()
time = 0
acerto = 0
tentativa = 0
rodando = False
timeString = "0:00.0"
frame = simplegui.create_frame("Home", 450, 300)
frame.set_draw_handler(draw_handler)
frame.start()
comecar = frame.add_button('Começar', comecar_handler)
parar = frame.add_button('Parar', parar_handler)
resetar = frame.add_button('Resetar', resetar_handler)
timer = simplegui.create_timer(100, timer_handler)
resetar_handler()