Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. import  simplegui
  2. t = 0
  3. time = '0:00.0'
  4. count = 0
  5. win_count = 0
  6. flag = 0
  7. def format(t):
  8.     global time
  9.     ms = t % 100
  10.     sec = (t - ms) / 100
  11.     minutes = sec // 60
  12.     seconds = sec % 60
  13.     if seconds >= 10:
  14.         time = str(int(minutes)) + ':' + str(int(seconds)) + '.' + str(ms//10)
  15.     else:
  16.         time = str(int(minutes)) + ':0' + str(int(seconds)) + '.' + str(ms//10)
  17.  
  18. def timer_handler():
  19.     global t
  20.     t = t + 10
  21.     format(t)
  22.  
  23. def button_handler1():
  24.     global t, time, count, win_count, flag
  25.     flag = 1
  26.     timer.start()
  27.  
  28.  
  29. def button_handler2():
  30.     global t, time, count, win_count, flag
  31.     timer.stop()
  32.     count = count + flag
  33.     if t % 100 == 0 and flag:
  34.         win_count = win_count + 1
  35.     flag = 0
  36.  
  37. def button_handler3():
  38.     global t, time, count, win_count, flag
  39.     timer.stop()
  40.     t = 0
  41.     time = '0:00.0'
  42.     count = 0
  43.     win_count = 0
  44.     flag = 0
  45.  
  46.  
  47. timer = simplegui.create_timer(100, timer_handler)
  48.  
  49.  
  50. def draw(canvas):
  51.     global t
  52.     canvas.draw_text(time, [90, 50], 40, 'White')
  53.     canvas.draw_text(str(win_count) + '/' + str(count), (210, 20), 20, "White")
  54.  
  55.  
  56.    
  57.  
  58. frame = simplegui.create_frame("Stopwatch", 250, 140)
  59.  
  60.  
  61. frame.set_draw_handler(draw)
  62. button1 = frame.add_button('Start', button_handler1,30)
  63. button2 = frame.add_button('Stop', button_handler2,30)
  64. button3 = frame.add_button('Reset', button_handler3,30)
  65.  
  66.  
  67. frame.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement