Skip to content

DropDownList

Create a drop-down list the user can pick items from.

Creating a DropDownList

You can create a DropDownList using the following functions:

dropdown = DropDownList()
DropDownList(items, action, color)
Parameter Type Default Description
items list[str] [] The items to show, for example ["item1", "item2", "item3"].
action function None The function to call when an item is picked; it receives one parameter, the selected item as a string.
color Color Color.LIGHT_GRAY The list color.

For example,

dropdown = DropDownList(["item1", "item2", "item3"], itemSelected)

where itemSelected is a function which expects one parameter, the selected item (a string).

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

Functions

Once a DropDownList dropdown has been created, the following functions are available:

Function Description
dropdown.setColor(color) Set the object's color.

Position

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

Size

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

Rotation

NOTE: Controls cannot be rotated. A control has these methods available, but they do nothing.

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

Visibility

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

Information

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

Hit Testing

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

Events

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