simpleguics2pygame — timer

simpleguics2pygame module: simpleguics2pygame/timer.

Class Timer.

Don’t require Pygame.

Piece of SimpleGUICS2Pygame.

license:GPLv3 — Copyright (C) 2015, 2020 Olivier Pirson
author:Olivier Pirson —
version:May 20, 2020
class SimpleGUICS2Pygame.simpleguics2pygame.timer.Timer(interval, timer_handler)[source]

Timer similar to SimpleGUI Timer of CodeSkulptor.

Don’t require Pygame.

__init__(interval, timer_handler)[source]

Set a time.

Don’t use directly, use create_timer().

  • interval – int or float > 0
  • timer_handler – function () -> *

Return ‘<Timer object>’.


list of weak references to the object (if defined)

classmethod _running_nb()[source]

Return the number of running timers.

Returns:int >= 0
classmethod _running_some()[source]
Returns:True if at least one timer running, else False
classmethod _stop_all()[source]

Stop all timers.

(Not available in SimpleGUI of CodeSkulptor.)

Side effect: Empty Timer._timers_running.

_timers_running = {}

Dict {(Timer id): Timer} of all timers are running.


Return the interval of this timer.

(Maybe available in SimpleGUI of CodeSkulptor but not in CodeSkulptor documentation!)

Returns:(int or float) > 0

If this timer is running then return True, else return False.


Start this timer.


With SimpleGUICS2Pygame, Frame.start() is blocking until Frame.stop() execution or closing window. So timers must be started before, and states must be initialized before. (Or maybe after by a handler function.)

(Side effect: Add id(self): self in Timer._timers_running.)


Stop this timer.

(Side effect: Remove id(self) of Timer. _timers_running.)

SimpleGUICS2Pygame.simpleguics2pygame.timer.create_timer(interval, timer_handler)[source]

Create and return a timer that will execute the function timer_handler every interval milliseconds.

The first execution of time_handler will take place after the first period.

(The timer can be started by Timer.start().)

  • interval – int or float > 0
  • timer_handler – function () -> *


SimpleGUICS2Pygame.simpleguics2pygame.timer.__all__ = ('Timer', 'create_timer')

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable’s items.

If the argument is a tuple, the return value is the same object.