Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import simplegui
- t = 0
- time = '0:00.0'
- count = 0
- win_count = 0
- flag = 0
- def format(t):
- global time
- ms = t % 100
- sec = (t - ms) / 100
- minutes = sec // 60
- seconds = sec % 60
- if seconds >= 10:
- time = str(int(minutes)) + ':' + str(int(seconds)) + '.' + str(ms//10)
- else:
- time = str(int(minutes)) + ':0' + str(int(seconds)) + '.' + str(ms//10)
- def timer_handler():
- global t
- t = t + 10
- format(t)
- def button_handler1():
- global t, time, count, win_count, flag
- flag = 1
- timer.start()
- def button_handler2():
- global t, time, count, win_count, flag
- timer.stop()
- count = count + flag
- if t % 100 == 0 and flag:
- win_count = win_count + 1
- flag = 0
- def button_handler3():
- global t, time, count, win_count, flag
- timer.stop()
- t = 0
- time = '0:00.0'
- count = 0
- win_count = 0
- flag = 0
- timer = simplegui.create_timer(100, timer_handler)
- def draw(canvas):
- global t
- canvas.draw_text(time, [90, 50], 40, 'White')
- canvas.draw_text(str(win_count) + '/' + str(count), (210, 20), 20, "White")
- frame = simplegui.create_frame("Stopwatch", 250, 140)
- frame.set_draw_handler(draw)
- button1 = frame.add_button('Start', button_handler1,30)
- button2 = frame.add_button('Stop', button_handler2,30)
- button3 = frame.add_button('Reset', button_handler3,30)
- frame.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement