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]#
Text input field for use inside a Toolbar.
Click into the field to focus it, then type to enter text. The text cursor can be moved with the arrow keys; BACKSPACE deletes the character left of the cursor and DELETE the character right of the cursor. At most
max_charscharacters can be entered.While the input has focus, the text cursor blinks; without focus, the cursor is hidden.
Examples
toolbar = Toolbar() name_input = Input((0, 0)) name_input.max_chars = 20 toolbar.add(name_input) world.camera.add_right(toolbar)
- 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")
CounterLabel#
FPSLabel#
- class miniworlds.actors.widgets.fps.FPSLabel(world=None, text='FPS', img_path=None)[source]#
Label that displays the measured frames per second.
The label measures the time between two frames itself; no clock object is required. Add it to a Toolbar so that it is updated once per frame.
- Parameters:
world – Optional world (ignored; kept for backward compatibility).
text – Prefix displayed before the measured value.
img_path – Optional path to an image shown alongside the text.
Examples
toolbar = Toolbar() toolbar.add(FPSLabel(text="FPS")) world.camera.add_right(toolbar)
TimeLabel#
- class miniworlds.actors.widgets.time.TimeLabel(world=None, text='Time', img_path=None)[source]#
Label that displays the current frame number of a world.
- Parameters:
world – The world whose frame counter is displayed. If no world is given, the world the widget is added to is used.
text – Prefix displayed before the frame number.
img_path – Optional path to an image shown alongside the text.
Examples
toolbar = Toolbar() toolbar.add(TimeLabel(world, text="Frame")) world.camera.add_right(toolbar)