Toggle objects are created using the following function. A toggle is specified by two diagonal corners, its beginning state, the function to call when the user presses it, its various colors (background, foreground, and outline), and outline thickness.
| Function | Description |
| Toggle(x1, y1, x2, y2, startState, updateFunction, foreground, background, outline, thickness) | Creates a toggle button.
|
You can create a toggle as follows:
from gui import *
d = Display()
# function to specify what happens when button is pressed
def printValue( value ):
if value: # if value is True, push toggle is on
print "Yes" # replace this with whatever you want done when on
else: # else value is False (i.e., push toggle is off)
print "No" # replace this with whatever you want done when off (if any)
t = Toggle(25, 25, 50, 50, False, printValue, Color.WHITE, Color.BLACK, Color.RED, 1)
d.add(t)
Once a toggle has been created, the following functions are available:
| Function | Description |
| t.getValue() | Returns the current value of the toggle (True or False). |
| t.setValue(value) | Sets the current value of the toggle to value. |