Actor > Widgets#

Knopf#

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

Öffentliche Datenattribute:

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 gibt an, wie Kollisionen überprüft werden sollen:

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 im letzten Frame

last_direction

costume_count

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

is_flipped

Wenn ein Actor gespiegelt wird, wird er entlang der y-Achse gespiegelt.

costume

Gets the costume of the actor, if available.

costumes

Ruft den Kostümmanager ab

orientation

direction

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

direction_at_unit_circle

Gibt die Richtung als Wert im Einheitskreis an (0° rechts, 90° oben, 180° links…)

size

Größe des Actors

width

Die Breite des Actors in Pixeln.

height

Die Höhe des Actors in Pixeln.

x

Der x-Wert eines Actors

y

Der y-Wert eines Actors

class_name

topleft_x

x-Wert der oberen linken Position des Actors

topleft_y

x-Wert der oberen linken Position des Actors

topleft

local_center

x-Wert der Actor-Mittelposition innerhalb des aktuellen Kamerabildschirms

center_x

x-Wert der Mittelpunktposition des Actors

center_y

y-Wert der Mittelpunktposition des Actors

center

is_rotatable

Legt fest, ob das Kostüm eines Actors drehbar sein soll.

static

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

fill_color

Die Füllfarbe des Actors als RGBA-Wert, z.B. (255, 0, 0) für Rot.

color

Die Füllfarbe des Actors als RGBA-Wert, z.B. (255, 0, 0) für Rot.

is_filled

Ist der Actor mit Farbe gefüllt?

border_color

Randfarbe des Actors.

stroke_color

Randfarbe des Actors.

border

Die Randgröße des Actors.

visible

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

world

image

Das Bild des Actors:

position

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

actor_id

speed

Inherited from ActorBase

dirty

Wenn der Actor schmutzig ist, wird er neu gezeichnet.

rect

Das umgebende Rechteck als pygame.Rect.

position_manager

sensor_manager

costume_manager

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

image

rect

layer

Dynamic, read only property for protected _layer attribute.

Öffentliche Methoden:

__init__([text, image])

on_clicked_left(mouse_pos)

This event is called when the button is clicked -

act()

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()

Dreht den Actor um 180° Grad.

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

has_costume()

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, direction])

Moves actor distance steps in current direction

move_vector(vector)

Moves actor in direction defined by the vector

move_back(distance)

undo_move()

Machen Sie den letzten Zug rückgängig.

move_towards(target)

move_in_direction(direction[, distance])

Bewegt den Actor distance Schritte in eine direction oder zu einer Position

move_to(position)

Bewegt den Actor distance zu einer bestimmten world_posiition

remove([kill])

Entfernt diesen Actor aus der Welt

before_remove()

bounce_from_border(borders)

“prallt” von einem Rand ab.

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

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?

is_inside_world()

Is the actor colliding with current ....

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 wird aufgerufen, wenn die Maus über den Actor bewegt wird :type position: :param position: Die Mausposition

on_mouse_leave(position)

on_mouse_over wird aufgerufen, wenn die Maus über den Actor bewegt wird :type position: :param position: Die Mausposition

on_mouse_left_down(position)

on_mouse_right_down(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_detecting_actor is called, when actor is detects a actor on same position

on_detecting_borders(borders)

on_detecting_border wird aufgerufen, wenn sich der Actor in der Nähe einer Grenze befindet

fill(value)

Füllfarbe für Ränder und Linien festlegen

hide()

Verbirgt einen Actor (der Actor wird unsichtbar)

show()

Zeigt einen Actor an (ein unsichtbarer Actor wird sichtbar)

register_sensor(*args, **kwargs)

This method is used for the @register_sensor decorator.

get_local_rect()

set_world(new_world)

new_costume()

set_position(value)

get_distance_to(obj)

Gets the distance to another actor or a position

on_shape_change()

Inherited from ActorBase

register(method[, force, name])

This method is used for the @register decorator.

register_message(*args, **kwargs)

Registriert eine Methode bei einem Objekt, um bestimmte on_message-Ereignisse zu behandeln.

__str__()

Gib str(self) zurück.

get_costume_class()

Inherited from DirtySprite

__init__(*groups)

__repr__()

Gib repr(self) zurück.

Inherited from Sprite

__init__(*groups)

add(*groups)

füge den Sprite zu Gruppen hinzu

remove(*groups)

entferne den Sprite aus den Gruppen

add_internal(group)

Um diesen Sprite intern zu einer Gruppe hinzuzufügen.

remove_internal(group)

For removing this sprite from a group internally.

update(*args, **kwargs)

method to control sprite behavior

kill()

entferne den Sprite aus allen Gruppen

groups()

Liste der Gruppen, die diesen Sprite enthalten

alive()

gehört der Sprite zu irgendwelchen Gruppen

__repr__()

Gib repr(self) zurück.

Private Datenattribute:

_abc_impl

Inherited from SingleWidget

_abc_impl

Inherited from BaseWidget

_abc_impl

Inherited from ParentActor

_abc_impl

Inherited from Actor

_abc_impl

_world

_sensor_manager

_position_manager

_costume_manager

_collision_type

_layer

_is_acting

__image

__rect

Inherited from ActorBase

_abc_impl

__image

__rect

Private Methoden:

Inherited from Actor

_validate_arguments(position, *args, **kwargs)

Inherited from ActorBase

_is_actor_repainted()

Inherited from DirtySprite

_set_visible(val)

den sichtbaren Wert (0 oder 1) festlegen und den Sprite als verändert markieren

_get_visible()

den sichtbaren Wert dieses Sprites zurückgeben


act()[Quellcode]#
on_clicked_left(mouse_pos)[Quellcode]#

This event is called when the button is clicked -

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

Beispiele

Senden Sie ein Ereignis bei einem Button-Klick:

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

Etikett#

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

Öffentliche Datenattribute:

Inherited from Button

fixed_width

children

actor_count

class_image

actor_id

speed

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.

fixed_width

children

actor_count

class_image

actor_id

speed

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

fixed_width

children

actor_count

class_image

actor_id

speed

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.

children

actor_count

class_image

actor_id

speed

Inherited from Actor

actor_count

class_image

origin

collision_type

collision_type gibt an, wie Kollisionen überprüft werden sollen:

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 im letzten Frame

last_direction

costume_count

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

is_flipped

Wenn ein Actor gespiegelt wird, wird er entlang der y-Achse gespiegelt.

costume

Gets the costume of the actor, if available.

costumes

Ruft den Kostümmanager ab

orientation

direction

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

direction_at_unit_circle

Gibt die Richtung als Wert im Einheitskreis an (0° rechts, 90° oben, 180° links…)

size

Größe des Actors

width

Die Breite des Actors in Pixeln.

height

Die Höhe des Actors in Pixeln.

x

Der x-Wert eines Actors

y

Der y-Wert eines Actors

class_name

topleft_x

x-Wert der oberen linken Position des Actors

topleft_y

x-Wert der oberen linken Position des Actors

topleft

local_center

x-Wert der Actor-Mittelposition innerhalb des aktuellen Kamerabildschirms

center_x

x-Wert der Mittelpunktposition des Actors

center_y

y-Wert der Mittelpunktposition des Actors

center

is_rotatable

Legt fest, ob das Kostüm eines Actors drehbar sein soll.

static

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

fill_color

Die Füllfarbe des Actors als RGBA-Wert, z.B. (255, 0, 0) für Rot.

color

Die Füllfarbe des Actors als RGBA-Wert, z.B. (255, 0, 0) für Rot.

is_filled

Ist der Actor mit Farbe gefüllt?

border_color

Randfarbe des Actors.

stroke_color

Randfarbe des Actors.

border

Die Randgröße des Actors.

visible

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

world

image

Das Bild des Actors:

position

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

actor_id

speed

Inherited from ActorBase

dirty

Wenn der Actor schmutzig ist, wird er neu gezeichnet.

rect

Das umgebende Rechteck als pygame.Rect.

position_manager

sensor_manager

costume_manager

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

image

rect

layer

Dynamic, read only property for protected _layer attribute.

Öffentliche Methoden:

__init__(text[, image])

Inherited from Button

__init__([text, image])

on_clicked_left(mouse_pos)

This event is called when the button is clicked -

act()

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()

Dreht den Actor um 180° Grad.

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

has_costume()

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, direction])

Moves actor distance steps in current direction

move_vector(vector)

Moves actor in direction defined by the vector

move_back(distance)

undo_move()

Machen Sie den letzten Zug rückgängig.

move_towards(target)

move_in_direction(direction[, distance])

Bewegt den Actor distance Schritte in eine direction oder zu einer Position

move_to(position)

Bewegt den Actor distance zu einer bestimmten world_posiition

remove([kill])

Entfernt diesen Actor aus der Welt

before_remove()

bounce_from_border(borders)

“prallt” von einem Rand ab.

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

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?

is_inside_world()

Is the actor colliding with current ....

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 wird aufgerufen, wenn die Maus über den Actor bewegt wird :type position: :param position: Die Mausposition

on_mouse_leave(position)

on_mouse_over wird aufgerufen, wenn die Maus über den Actor bewegt wird :type position: :param position: Die Mausposition

on_mouse_left_down(position)

on_mouse_right_down(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_detecting_actor is called, when actor is detects a actor on same position

on_detecting_borders(borders)

on_detecting_border wird aufgerufen, wenn sich der Actor in der Nähe einer Grenze befindet

fill(value)

Füllfarbe für Ränder und Linien festlegen

hide()

Verbirgt einen Actor (der Actor wird unsichtbar)

show()

Zeigt einen Actor an (ein unsichtbarer Actor wird sichtbar)

register_sensor(*args, **kwargs)

This method is used for the @register_sensor decorator.

get_local_rect()

set_world(new_world)

new_costume()

set_position(value)

get_distance_to(obj)

Gets the distance to another actor or a position

on_shape_change()

Inherited from ActorBase

register(method[, force, name])

This method is used for the @register decorator.

register_message(*args, **kwargs)

Registriert eine Methode bei einem Objekt, um bestimmte on_message-Ereignisse zu behandeln.

__str__()

Gib str(self) zurück.

get_costume_class()

Inherited from DirtySprite

__init__(*groups)

__repr__()

Gib repr(self) zurück.

Inherited from Sprite

__init__(*groups)

add(*groups)

füge den Sprite zu Gruppen hinzu

remove(*groups)

entferne den Sprite aus den Gruppen

add_internal(group)

Um diesen Sprite intern zu einer Gruppe hinzuzufügen.

remove_internal(group)

For removing this sprite from a group internally.

update(*args, **kwargs)

method to control sprite behavior

kill()

entferne den Sprite aus allen Gruppen

groups()

Liste der Gruppen, die diesen Sprite enthalten

alive()

gehört der Sprite zu irgendwelchen Gruppen

__repr__()

Gib repr(self) zurück.

Private Datenattribute:

_abc_impl

Inherited from Button

_abc_impl

_visible

_layer

_world

_sensor_manager

_position_manager

_costume_manager

_collision_type

_is_acting

__image

__rect

Inherited from SingleWidget

_abc_impl

_visible

_layer

_world

_sensor_manager

_position_manager

_costume_manager

_collision_type

_is_acting

__image

__rect

Inherited from BaseWidget

_abc_impl

_visible

_layer

_world

_sensor_manager

_position_manager

_costume_manager

_collision_type

_is_acting

__image

__rect

Inherited from ParentActor

_abc_impl

_visible

_layer

_world

_sensor_manager

_position_manager

_costume_manager

_collision_type

_is_acting

__image

__rect

Inherited from Actor

_abc_impl

_world

_sensor_manager

_position_manager

_costume_manager

_collision_type

_layer

_is_acting

__image

__rect

Inherited from ActorBase

_abc_impl

__image

__rect

Private Methoden:

Inherited from Actor

_validate_arguments(position, *args, **kwargs)

Inherited from ActorBase

_is_actor_repainted()

Inherited from DirtySprite

_set_visible(val)

den sichtbaren Wert (0 oder 1) festlegen und den Sprite als verändert markieren

_get_visible()

den sichtbaren Wert dieses Sprites zurückgeben