Actor > Widgets

Actor > Widgets#

Button#

class miniworlds.actors.widgets.button.Button(position: Tuple[float, float] | None = (0, 0), *args, **kwargs)[source]#

Public Data Attributes:

Inherited from SingleWidget

padding_left

padding_right

padding_top

padding_bottom

position

The position of the actor as Position(x, y)

topleft

center

row_height

text_align

Defines how text is aligned.

text

The text which is displayed on the widget.

Inherited from BaseWidget

padding_left

padding_right

padding_top

padding_bottom

position

The position of the actor as Position(x, y)

topleft

center

row_height

Inherited from ParentActor

visible

You can make this sprite disappear without removing it from the group assign 0 for invisible and 1 for visible

layer

Defines the layer on which the actor is drawn if several actors overlap.

Inherited from Actor

actor_count

class_image

origin

collision_type

collision_type specifies how collisions should be checked:

is_blockable

A actor with the property is_blockable cannot move through actors with the property is_blocking.

is_blocking

A actor with the property is_blockable cannot move through actors with the property is_blocking.

layer

Defines the layer on which the actor is drawn if several actors overlap.

last_position

Actor position in last frame

last_direction

costume_count

Returns number of costumes of actor, 0 if actor has no costume

is_flipped

When a actor is mirrored, it is mirrored across the y-axis.

costume

Gets the costume of actor

costumes

Gets the costume manager

orientation

direction

Directions are handled exactly as in the Scratch programming language, see: Scratch Wiki

direction_at_unit_circle

Gets the direction as value in unit circle (0° right, 90° top, 180° left...)

dirty

If actor is dirty, it will be repainted.

size

Size of the actor

width

The width of the actor in pixels.

height

The height of the actor in pixels.

x

The x-value of a actor

y

The y-value of a actor

class_name

topleft_x

x-value of actor topleft-position

topleft_y

x-value of actor topleft-position

topleft

local_center

x-value of actor center-position inside the current camera-screen

center_x

x-value of actor center-position

center_y

y-value of actor center-position

center

is_rotatable

Defines if the costume of a actor should be rotatable.

static

Should actor react to events? You can turn this option off for additional performance boost.

fill_color

The fill color of actor as rgba value, e.g. (255, 0, 0) for red.

color

The fill color of actor as rgba value, e.g. (255, 0, 0) for red.

is_filled

Is actor filled with color?

border_color

border color of actor.

stroke_color

border color of actor.

border

The border-size of actor.

visible

You can make this sprite disappear without removing it from the group assign 0 for invisible and 1 for visible

rect

The surrounding Rectangle as pygame.Rect.

world

image

The image of the actor:

position_manager

sensor_manager

costume_manager

position

The position of the actor as Position(x, y)

is_display_initialized

actor_id

children

speed

ask

Inherited from DirtySprite

visible

You can make this sprite disappear without removing it from the group assign 0 for invisible and 1 for visible

layer

Layer property can only be set before the sprite is added to a group, after that it is read only and a sprite's layer in a group should be set via the group's change_layer() method.

Inherited from Sprite

layer

Dynamic, read only property for protected _layer attribute.

Public Methods:

__init__([text, image])

on_clicked_left(mouse_pos)

This event is called when the button is clicked -

Inherited from SingleWidget

__init__([position])

resize()

cut_widget_text()

update_positions()

get_local_pos(position)

set_row_height([value])

set_border([color, width])

sets border of widget

set_position(value)

set_world(new_world)

get_widget_text()

set_image(_img_source)

sets image of widget

set_text(text)

Sets text of widget.

get_text()

Inherited from BaseWidget

__init__([position])

new_costume()

resize()

update_positions()

get_local_pos(position)

set_row_height(value)

set_border([color, width])

sets border of widget

set_world(new_world)

set_position(value)

Inherited from ParentActor

__init__(position[, children])

add_child(actor)

set_layer(value)

set_world(new_world)

reset_costumes()

before_remove()

Inherited from Actor

__init__([position])

switch_origin(value)

create_on_world(world)

Creates a actor to a specific world

from_topleft(topleft_position, *args, **kwargs)

Creates a actor with center at center_position

from_center(center_position, *args, **kwargs)

Creates a actor with center at center_position

flip_x()

Flips the actor by 180° degrees.

add_costume([source])

Adds a new costume to actor.

add_costumes(sources)

Adds multiple costumes

remove_costume([source])

Removes a costume from actor

switch_costume(source)

Switches the costume of actor

set_costume(costume)

reset_costumes()

set_background_color(color)

next_costume()

Switches to the next costume of actor

turn_left([degrees])

Turns actor by degrees degrees left :rtype: int

turn_right([degrees])

Turns actor by degrees degrees right

set_direction(direction)

Actor points in given direction.

point_towards_position(destination)

Actor points towards a given position

point_towards_actor(other)

Actor points towards another actor.

set_size(value)

scale_width(value)

scale_height(value)

move([distance])

Moves actor distance steps in current direction

move_vector(vector)

Moves actor in direction defined by the vector

move_up([distance])

move_down([distance])

move_left([distance])

move_right([distance])

move_back(distance)

undo_move()

Undo the last move.

move_towards(target)

move_in_direction(direction[, distance])

Moves actor distance steps into a direction or towards a position

move_to(position)

Moves actor distance to a specific world_posiition

remove([kill])

Removes this actor from world

before_remove()

bounce_from_border(borders)

The actor "bounces" from a border.

detect_all([actors, direction, distance])

Detects if actors are on actor position.

detect(*args, **kwargs)

Detects if actors are on actor position.

detect_borders([distance])

Detects borders :rtype: List

detect_left_border()

Does the actor touch the left border?

detect_right_border()

Does the actor touch the right border?

detect_top_border()

Does the actor touch the lower border?

detecting_bottom_border()

Does the actor touch the lower border?

detect_color([color])

Detects colors in world-background at actor center-position

detect_color_at([direction, distance])

Detects colors in world-background at actor-position

detect_actors_at([direction, distance, actors])

Detects a actor in given direction and distance.

detect_actor_at([direction, distance, actors])

detect_actors_in_front([actors, distance])

detect_actor_in_front([actors, distance])

detect_point(position)

Is the actor colliding with a specific (global) point?

detect_pixel(position)

Is the actor colliding with a pixel?

detect_rect(rect)

Is the actor colliding with a static rect?

detect_world()

Is the actor colliding with a static rect?

bounce_from_actor(other)

animate([speed])

animate_costume(costume[, speed])

animate_loop([speed])

Animates a costume with a looping animation

stop_animation()

Stops current animation.

send_message(message)

Sends a message to world.

on_key_down(key)

on_key_down is called one time when a key is pressed down.

on_key_pressed(key)

on_key_pressed is called when while key is pressed.

on_key_up(key)

on_mouse_over(position)

on_mouse_over is called, when mouse is moved over actor :type position: :param position: The mouse position

on_mouse_leave(position)

on_mouse_over is called, when mouse is moved over actor :type position: :param position: The mouse position

on_mouse_left(position)

on_mouse_left is called when left mouse button was pressed.

on_mouse_right(position)

Method is called when right mouse button was pressed.

on_mouse_motion(position)

Method is called when mouse moves.

on_mouse_left_released(position)

Method is called when left mouse key is released.

on_mouse_right_released(position)

Method is called when right mouse key is released.

on_clicked_left(position)

The mouse is on top of a actor and mouse was clicked.

on_clicked_right(position)

The mouse is on top of a actor and mouse was clicked.

on_detecting_world()

on_detecting_world is called, when actor is on the world

on_not_detecting_world()

on_detecting_world is called, when actor is on the world

on_detecting_actor(actor)

on_detect_actor is called, when actor is detects a actor on same position

on_detecting_borders(borders)

on_detecting_border is called, when actor is near a border

fill(value)

Set fill color for borders and lines

hide()

Hides a actor (the actor will be invisible)

show()

Displays a actor ( an invisible actor will be visible)

register(method[, force, name])

This method is used for the @register decorator.

register_message(*args, **kwargs)

This method is used for the @register_message decorator.

register_sensor(*args, **kwargs)

This method is used for the @register_sensor decorator.

get_local_rect()

__str__()

Return str(self).

set_world(new_world)

new_costume()

get_costume_class()

set_position(value)

get_distance_to(obj)

Gets the distance to another actor or a position

on_shape_change()

Inherited from DirtySprite

__init__(*groups)

__repr__()

Return repr(self).

Inherited from Sprite

__init__(*groups)

add(*groups)

add the sprite to groups

remove(*groups)

remove the sprite from groups

add_internal(group)

For adding this sprite to a group internally.

remove_internal(group)

For removing this sprite from a group internally.

update(*args, **kwargs)

method to control sprite behavior

kill()

remove the Sprite from all Groups

groups()

list of Groups that contain this Sprite

alive()

does the sprite belong to any groups

__repr__()

Return repr(self).

Private Data Attributes:

Inherited from Actor

_world

_sensor_manager

_position_manager

_costume_manager

_collision_type

_layer

_is_acting

Private Methods:

Inherited from Actor

_validate_arguments(position, *args, **kwargs)

Inherited from DirtySprite

_set_visible(val)

set the visible value (0 or 1) and makes the sprite dirty

_get_visible()

return the visible value of that sprite


on_clicked_left(mouse_pos)[source]#

This event is called when the button is clicked -

By default, a message with the button text is then sent to the world.

Examples

Send a event on button-click:

toolbar = Toolbar()
button = Button("Start Rocket")
button.world = toolbar
world.add_right(toolbar)

@world.register
def on_message(self, message):
    if message == "Start Rocket":
        rocket.started = True

Label#

class miniworlds.actors.widgets.label.Label(position: Tuple[float, float] | None = (0, 0), *args, **kwargs)[source]#

Public Data Attributes:

Inherited from SingleWidget

padding_left

padding_right

padding_top

padding_bottom

position

The position of the actor as Position(x, y)

topleft

center

row_height

text_align

Defines how text is aligned.

text

The text which is displayed on the widget.

Inherited from BaseWidget

padding_left

padding_right

padding_top

padding_bottom

position

The position of the actor as Position(x, y)

topleft

center

row_height

Inherited from ParentActor

visible

You can make this sprite disappear without removing it from the group assign 0 for invisible and 1 for visible

layer

Defines the layer on which the actor is drawn if several actors overlap.

Inherited from Actor

actor_count

class_image

origin

collision_type

collision_type specifies how collisions should be checked:

is_blockable

A actor with the property is_blockable cannot move through actors with the property is_blocking.

is_blocking

A actor with the property is_blockable cannot move through actors with the property is_blocking.

layer

Defines the layer on which the actor is drawn if several actors overlap.

last_position

Actor position in last frame

last_direction

costume_count

Returns number of costumes of actor, 0 if actor has no costume

is_flipped

When a actor is mirrored, it is mirrored across the y-axis.

costume

Gets the costume of actor

costumes

Gets the costume manager

orientation

direction

Directions are handled exactly as in the Scratch programming language, see: Scratch Wiki

direction_at_unit_circle

Gets the direction as value in unit circle (0° right, 90° top, 180° left...)

dirty

If actor is dirty, it will be repainted.

size

Size of the actor

width

The width of the actor in pixels.

height

The height of the actor in pixels.

x

The x-value of a actor

y

The y-value of a actor

class_name

topleft_x

x-value of actor topleft-position

topleft_y

x-value of actor topleft-position

topleft

local_center

x-value of actor center-position inside the current camera-screen

center_x

x-value of actor center-position

center_y

y-value of actor center-position

center

is_rotatable

Defines if the costume of a actor should be rotatable.

static

Should actor react to events? You can turn this option off for additional performance boost.

fill_color

The fill color of actor as rgba value, e.g. (255, 0, 0) for red.

color

The fill color of actor as rgba value, e.g. (255, 0, 0) for red.

is_filled

Is actor filled with color?

border_color

border color of actor.

stroke_color

border color of actor.

border

The border-size of actor.

visible

You can make this sprite disappear without removing it from the group assign 0 for invisible and 1 for visible

rect

The surrounding Rectangle as pygame.Rect.

world

image

The image of the actor:

position_manager

sensor_manager

costume_manager

position

The position of the actor as Position(x, y)

is_display_initialized

actor_id

children

speed

ask

Inherited from DirtySprite

visible

You can make this sprite disappear without removing it from the group assign 0 for invisible and 1 for visible

layer

Layer property can only be set before the sprite is added to a group, after that it is read only and a sprite's layer in a group should be set via the group's change_layer() method.

Inherited from Sprite

layer

Dynamic, read only property for protected _layer attribute.

Public Methods:

__init__(text[, image])

Inherited from Button

__init__([text, image])

on_clicked_left(mouse_pos)

This event is called when the button is clicked -

Inherited from SingleWidget

__init__([position])

resize()

cut_widget_text()

update_positions()

get_local_pos(position)

set_row_height([value])

set_border([color, width])

sets border of widget

set_position(value)

set_world(new_world)

get_widget_text()

set_image(_img_source)

sets image of widget

set_text(text)

Sets text of widget.

get_text()

Inherited from BaseWidget

__init__([position])

new_costume()

resize()

update_positions()

get_local_pos(position)

set_row_height(value)

set_border([color, width])

sets border of widget

set_world(new_world)

set_position(value)

Inherited from ParentActor

__init__(position[, children])

add_child(actor)

set_layer(value)

set_world(new_world)

reset_costumes()

before_remove()

Inherited from Actor

__init__([position])

switch_origin(value)

create_on_world(world)

Creates a actor to a specific world

from_topleft(topleft_position, *args, **kwargs)

Creates a actor with center at center_position

from_center(center_position, *args, **kwargs)

Creates a actor with center at center_position

flip_x()

Flips the actor by 180° degrees.

add_costume([source])

Adds a new costume to actor.

add_costumes(sources)

Adds multiple costumes

remove_costume([source])

Removes a costume from actor

switch_costume(source)

Switches the costume of actor

set_costume(costume)

reset_costumes()

set_background_color(color)

next_costume()

Switches to the next costume of actor

turn_left([degrees])

Turns actor by degrees degrees left :rtype: int

turn_right([degrees])

Turns actor by degrees degrees right

set_direction(direction)

Actor points in given direction.

point_towards_position(destination)

Actor points towards a given position

point_towards_actor(other)

Actor points towards another actor.

set_size(value)

scale_width(value)

scale_height(value)

move([distance])

Moves actor distance steps in current direction

move_vector(vector)

Moves actor in direction defined by the vector

move_up([distance])

move_down([distance])

move_left([distance])

move_right([distance])

move_back(distance)

undo_move()

Undo the last move.

move_towards(target)

move_in_direction(direction[, distance])

Moves actor distance steps into a direction or towards a position

move_to(position)

Moves actor distance to a specific world_posiition

remove([kill])

Removes this actor from world

before_remove()

bounce_from_border(borders)

The actor "bounces" from a border.

detect_all([actors, direction, distance])

Detects if actors are on actor position.

detect(*args, **kwargs)

Detects if actors are on actor position.

detect_borders([distance])

Detects borders :rtype: List

detect_left_border()

Does the actor touch the left border?

detect_right_border()

Does the actor touch the right border?

detect_top_border()

Does the actor touch the lower border?

detecting_bottom_border()

Does the actor touch the lower border?

detect_color([color])

Detects colors in world-background at actor center-position

detect_color_at([direction, distance])

Detects colors in world-background at actor-position

detect_actors_at([direction, distance, actors])

Detects a actor in given direction and distance.

detect_actor_at([direction, distance, actors])

detect_actors_in_front([actors, distance])

detect_actor_in_front([actors, distance])

detect_point(position)

Is the actor colliding with a specific (global) point?

detect_pixel(position)

Is the actor colliding with a pixel?

detect_rect(rect)

Is the actor colliding with a static rect?

detect_world()

Is the actor colliding with a static rect?

bounce_from_actor(other)

animate([speed])

animate_costume(costume[, speed])

animate_loop([speed])

Animates a costume with a looping animation

stop_animation()

Stops current animation.

send_message(message)

Sends a message to world.

on_key_down(key)

on_key_down is called one time when a key is pressed down.

on_key_pressed(key)

on_key_pressed is called when while key is pressed.

on_key_up(key)

on_mouse_over(position)

on_mouse_over is called, when mouse is moved over actor :type position: :param position: The mouse position

on_mouse_leave(position)

on_mouse_over is called, when mouse is moved over actor :type position: :param position: The mouse position

on_mouse_left(position)

on_mouse_left is called when left mouse button was pressed.

on_mouse_right(position)

Method is called when right mouse button was pressed.

on_mouse_motion(position)

Method is called when mouse moves.

on_mouse_left_released(position)

Method is called when left mouse key is released.

on_mouse_right_released(position)

Method is called when right mouse key is released.

on_clicked_left(position)

The mouse is on top of a actor and mouse was clicked.

on_clicked_right(position)

The mouse is on top of a actor and mouse was clicked.

on_detecting_world()

on_detecting_world is called, when actor is on the world

on_not_detecting_world()

on_detecting_world is called, when actor is on the world

on_detecting_actor(actor)

on_detect_actor is called, when actor is detects a actor on same position

on_detecting_borders(borders)

on_detecting_border is called, when actor is near a border

fill(value)

Set fill color for borders and lines

hide()

Hides a actor (the actor will be invisible)

show()

Displays a actor ( an invisible actor will be visible)

register(method[, force, name])

This method is used for the @register decorator.

register_message(*args, **kwargs)

This method is used for the @register_message decorator.

register_sensor(*args, **kwargs)

This method is used for the @register_sensor decorator.

get_local_rect()

__str__()

Return str(self).

set_world(new_world)

new_costume()

get_costume_class()

set_position(value)

get_distance_to(obj)

Gets the distance to another actor or a position

on_shape_change()

Inherited from DirtySprite

__init__(*groups)

__repr__()

Return repr(self).

Inherited from Sprite

__init__(*groups)

add(*groups)

add the sprite to groups

remove(*groups)

remove the sprite from groups

add_internal(group)

For adding this sprite to a group internally.

remove_internal(group)

For removing this sprite from a group internally.

update(*args, **kwargs)

method to control sprite behavior

kill()

remove the Sprite from all Groups

groups()

list of Groups that contain this Sprite

alive()

does the sprite belong to any groups

__repr__()

Return repr(self).

Private Data Attributes:

Inherited from Actor

_world

_sensor_manager

_position_manager

_costume_manager

_collision_type

_layer

_is_acting

Private Methods:

Inherited from Actor

_validate_arguments(position, *args, **kwargs)

Inherited from DirtySprite

_set_visible(val)

set the visible value (0 or 1) and makes the sprite dirty

_get_visible()

return the visible value of that sprite