#!/usr/local/bin/python ## # Timer # ----- # Every program can have a timer. This program demonstrates the # use of the timer function. # # Use settimerfn to set the call-back function which is called by # the timer. The call-back takes one parameter and returns nothing. # # Use settimer to start or stop the timer. The number passed to # this function is the number of milliseconds between timeouts. # In the example, the function draw_something will occur every # 5 seconds (5000 milliseconds). # # Because the timer call-back is not associated with a particular # window, it must use the drawto function to explicitly allow # drawing to a window. Ordinarily a call-back which belongs to a # window is set up to draw to the window when it is called. ## from graphapp import * global r def draw_something(w): global r drawto(w) drawellipse(r) r.x = r.x + 10 r.y = r.y + 10 def main(): global r w = newwindow("Timer", rect(20,20,400,300), StandardWindow) show(w) r = rect(10,10,30,15) settimerfn(draw_something, w) settimer(2000) draw_something(w) mainloop() main()