Skip to content

CheckBox

Create a checkbox the user can check and uncheck.

Creating a CheckBox

You can create a CheckBox using the following functions:

CheckBox()
CheckBox(text, action, color)
Parameter Type Default Description
text str '' The text shown beside the checkbox.
action function None The function to call when the checkbox changes; it receives one parameter, True if it was just checked or False if it was just unchecked.
color Color Color.CLEAR The checkbox color.

For example,

checkbox = Checkbox("Check Me Out!")

Once created, you can add it to a Display using the Display's add() function.

Functions

Once a CheckBox checkbox has been created, the following functions are available:

Function Description
checkbox.getText() Return the object's text.
checkbox.setText(text) Set the object's text.
checkbox.setColor(color) Set the object's color.

Checking State

If you create a CheckBox without a callback function, it is a passive GUI element. You can still check whether the CheckBox is checked or unchecked using these functions:

Function Description
checkbox.check() Check the checkbox.
checkbox.uncheck() Uncheck the checkbox.
checkbox.isChecked() Report whether the checkbox is checked.

Position

Function Description
checkbox.getPosition() Return the object's position, the top-left corner of its bounding box.
checkbox.getX() Return the object's horizontal position.
checkbox.getY() Return the object's vertical position.
checkbox.getCenter() Return the object's center point.
checkbox.getCenterX() Return the object's horizontal center.
checkbox.getCenterY() Return the object's vertical center.
checkbox.setPosition(x, y) Move the object so the top-left corner of its bounding box sits at the given point.
checkbox.setX(x) Set the object's horizontal position.
checkbox.setY(y) Set the object's vertical position.
checkbox.setCenter(x, y) Move the object so its center sits at the given point.
checkbox.setCenterX(x) Set the object's horizontal center.
checkbox.setCenterY(y) Set the object's vertical center.
checkbox.move(x, y) Move the object to a new position.

Size

Function Description
checkbox.getSize() Return the object's width and height.
checkbox.getWidth() Return the object's width.
checkbox.getHeight() Return the object's height.
checkbox.setSize(width, height) Set the object's width and height.
checkbox.setWidth(width) Set the object's width.
checkbox.setHeight(height) Set the object's height.

Rotation

NOTE: Controls cannot be rotated. Controls have these functions available, but they do nothing.

Function Description
checkbox.setRotation(rotation) Do nothing, since controls cannot be turned.
checkbox.getRotation() Return how far the object is turned.
checkbox.rotate(angle) Turn the object by an additional angle.

Visibility

Function Description
checkbox.getVisibility() Return how visible the object is.
checkbox.setVisibility(visibility) Set how visible the object is.

Information

Function Description
checkbox.getEndpoints() Return the object's four corners.
checkbox.getBoundingBox() Return the smallest upright box that surrounds the object.
checkbox.getGroup() Return the Group this object belongs to.
checkbox.getDisplay() Return the Display this object is on.
checkbox.setToolTipText() Set the hover text shown over the object.

Hit Testing

Function Description
checkbox.contains(x, y) Report whether a point lies inside the object.
checkbox.intersects(other) Report whether this object overlaps another.
checkbox.encloses(other) Report whether this object completely contains another.

Events

Function Description
checkbox.onMouseClick(action) Set up a function to call when the mouse is clicked on this object.
checkbox.onMouseDown(action) Set up a function to call when the mouse checkbox is pressed on this object.
checkbox.onMouseUp(action) Set up a function to call when the mouse checkbox is released over this object.
checkbox.onMouseMove(action) Set up a function to call when the mouse moves over this object.
checkbox.onMouseDrag(action) Set up a function to call when the mouse is dragged over this object.
checkbox.onMouseEnter(action) Set up a function to call when the mouse moves onto this object.
checkbox.onMouseExit(action) Set up a function to call when the mouse moves off this object.
checkbox.onKeyType(action) Set up a function to call when a key is typed (pressed and released).
checkbox.onKeyDown(action) Set up a function to call when a key is pressed down.
checkbox.onKeyUp(action) Set up a function to call when a key is released.