Actor > Widgets#
Use Button when a widget should simply send a message.
API Reference#
Label#
- class miniworlds.actors.widgets.label.Label(position: Tuple[float, float] | None = (0, 0), *args, **kwargs)[source]#
Text label for use in a Toolbar.
Label is usually used for headings, status text, scores, or other information that should be shown inside a toolbar.
- Parameters:
text – The text to display in the label.
image – Optional path to an image to show instead of (or alongside) text.
Examples
toolbar = Toolbar() score_label = Label("Score: 0") toolbar.add(score_label) world.camera.add_right(toolbar)
Input#
- class miniworlds.actors.widgets.input.Input(position: Tuple[float, float] | None = (0, 0), *args, **kwargs)[source]#
- property cursor_position#
- property max_chars#
- on_key_down(keys)[source]#
Called once when a key is pressed.
Register on_key_down_<letter> (for example on_key_down_a) if you want to react to a specific letter only.
For arrow keys use on_key_down_left, on_key_down_right, on_key_down_up, or on_key_down_down.
- Parameters:
key – List of key name variants, for example [“A”, “a”] or [“left”].
Examples
@player.register def on_key_down(self, key): if "left" in key: self.direction = "left" elif "right" in key: self.direction = "right" self.move() @player.register def on_key_down_space(self): self.send_message("jump")