Skip to content

Instantly share code, notes, and snippets.

@ricardovsilva
Last active February 3, 2016 13:25
Show Gist options
  • Save ricardovsilva/33434de1bce41fc00f97 to your computer and use it in GitHub Desktop.
Save ricardovsilva/33434de1bce41fc00f97 to your computer and use it in GitHub Desktop.
Example of code skulptor exercise that use timer
import simplegui
time = 0
points = 0
def format(time):
A = time // 600
B = time // 60
C = time % 60
D = 0
converted = str(A) + ":" + str(B) + str(C) + "." + str(D)
return converted
def start_button():
timer.start()
def stop_button():
#global points, time
timer.stop()
def reset_button():
global time
time = 0
return time
def timer_handler():
global time
time += 1
return time
def draw_time(canvas):
global time
text = format(time)
canvas.draw_text(text, [175,100], 15, "white")
frame = simplegui.create_frame("Stopwatch", 350, 200)
timer = simplegui.create_timer(1000, timer_handler)
frame.add_button("Start", start_button, 70)
frame.add_button("Stop", stop_button, 70)
frame.add_button("Reset", reset_button, 70)
frame.set_draw_handler(draw_time)
frame.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment