Last active
February 3, 2016 13:25
-
-
Save ricardovsilva/33434de1bce41fc00f97 to your computer and use it in GitHub Desktop.
Example of code skulptor exercise that use timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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