World > Toolbar#
- class miniworlds.worlds.gui.toolbar.Toolbar[source]#
A Toolbar contains widgets (Buttons, Labels, …)
Public Data Attributes:
Background color as Tuple, e.g. (255,255,255) for white.
Defines left margin
Defines right margin
Defines top margin
Defines bottom margin
Inherited from
World
Step defines how often the method
act()
will be called.Frames per second shown on the screen.
The x-world_size (defaults to view_size)
The y-world_size (defaults to view_size)
Set the size of world
Set default fill color for borders and lines
Set default stroke color for borders and lines.
Set default border color for borders and lines.
Sets default border color for actors
Returns all backgrounds of the world as list.
Returns the current background
The current displayed image
Gets the parent window
Inherited from
WorldBase
surface
window
size
rect
topleft
window_docking_position
width
height
Public Methods:
__init__
()Base class for toolbars.
implemented in subclasses
remove
(item)Removes a widget from the toolbar.
has_widget
(key)Checks if self.widgets has key
get_widget
(key)Gets widget by key
reorder
()update
()The mainloop, called once per frame.
send_message
(text)Sends broadcast message
scroll_up
(value)scroll_down
(value)can_scroll_down
(value)can_scroll_up
(value)on_new_actor
(actor)on_remove_actor
(actor)Inherited from
GUI
add
(actor)Inherited from
World
validate_parameters
(x, y)__init__
([x, y])add_right
(world[, size])add_bottom
(world[, size])remove_world
(container)get_world_connector
(actor)detect_position
(pos)Checks if position is in the world.
contains_rect
(rect)Detects if rect is completely on the world.
set_columns
(value)set_rows
(value)borders
(value)Gets all borders from a source (Position or Rect).
default_fill
(value)Set default fill color for borders and lines
Returns the current background
switch_background
(background)Switches the background
remove_background
([background])Removes a background from world
set_background
(source)Adds a new background to the world
add_background
(source)Adds a new background to the world
start
()Starts the world, if world is not running.
stop
([frames])Stops the world.
run
([fullscreen, fit_desktop, replit, ...])The method show() should always be called at the end of your program.
play_sound
(path)plays sound from path
play_music
(path)plays a music from path
stops a music
Gets the current mouse_position
Gets x-coordinate of mouse-position
Gets y-coordinate of mouse-position
gets mouse-position of last frame
Returns True, if mouse is pressed
Returns True, if mouse left button is pressed
Returns True, if mouse right button is pressed
is_in_world
(position)send_message
(message[, data])Sends broadcast message
quit
([exit_code])quits app and closes the window
reset
()Resets the world Creates a new world with init-function - recreates all actors and actors on the world.
clear
()switch_world
(new_world[, reset])Switches to another world
get_color_from_pixel
(position)Returns the color at a specific position
get_from_pixel
(position)Gets Position from pixel
to_pixel
(position)on_setup
()Overwrite or register this method to call on_setup-Actions
add_to_world
(actor, position)Adds a Actor to the world.
detect_actors
(position)Gets all actors which are found at a specific position.
get_actors_from_pixel
(pixel)repaint
()Implemented in subclasses
update
()The mainloop, called once per frame.
handle_event
(event[, data])Event handling
register
(method)Used as decorator e.g. @register def method.
unregister
(method)direction
(point1, point2)distance_to
(pos1, pos2)direction_to
(pos1, pos2)load_world_from_db
(file)Loads a sqlite db file.
load_actors_from_db
(file, actor_classes)Loads all actors from db.
save_to_db
(file)Saves the current world an all actors to database.
screenshot
([filename])Creates a screenshot in given file.
get_columns_by_width
(width)get_rows_by_height
(height)Gets a set of all events you can register
Inherited from
WorldBase
__init__
()on_change
()implemented in subclasses
add_to_window
(app, dock[, size])update_width_and_height
()repaint
()Implemented in subclasses
blit_surface_to_window_surface
()remove
(actor)Implemented in subclasses
handle_event
(event, data)get_event
(event, data)Implemented in subclasses
update
()Implemented in subclasses
get_local_position
(position)on_new_actor
(actor)on_remove_actor
(actor)Private Data Attributes:
_abc_impl
Inherited from
GUI
_abc_impl
Inherited from
World
_abc_impl
_fps
_key_pressed
_animated
_is_filled
_orientation
_static
_step
_registered_methods
Inherited from
WorldBase
_abc_impl
Inherited from
ABC
_abc_impl
Private Methods:
_add_widget
(widget[, key])_widgets_total_height
()_set_widget_width
(widget)Inherited from
GUI
_get_world_connector_class
()needed by get_world_connector in parent class
Inherited from
World
_get_camera_manager_class
()_get_world_connector_class
()needed by get_world_connector in parent class
_create_event_manager
()_update_all_costumes
()updates costumes for all actors on the world
_act_all
()Overwritten in subclasses, e.g. physics_world.
_tick_timed_objects
()
- __init__()[source]#
Base class for toolbars.
Example
Add a Toolbar which interacts with Actors on world via messages:
from miniworlds import * world = World() world.add_background("images/galaxy.jpg") toolbar = Toolbar() button = Button("Start Rocket") toolbar.add(button) world.add_container.add_right(toolbar) @world.register def on_message(self, message): if message == "Start Rocket": rocket.started = True rocket = Actor(100, 200) rocket.add_costume("images/ship.png") rocket.started = False rocket.turn_left(90) rocket.direction = "up" @rocket.register def act(self): if self.started: self.move() @rocket.register def on_sensing_not_on_the_world(self): self.remove() world.run()
- property background_color#
Background color as Tuple, e.g. (255,255,255) for white
- can_scroll_down(value)[source]#
- Parameters:
value (_type_) – _description_
- Returns:
_description_
- Return type:
_type_
- get_widget(key)[source]#
Gets widget by key
- Return type:
BaseWidget
- Returns:
_description_
- Return type:
_type_
- property padding_bottom#
Defines bottom margin
- property padding_left#
Defines left margin
- property padding_right#
Defines right margin
- property padding_top#
Defines top margin
- remove(item)[source]#
Removes a widget from the toolbar. Warning: Be careful when calling this method in a loop.
- Parameters:
key – The key of widget which should be removed
- send_message(text)[source]#
Sends broadcast message
A message can be received by the world or any actor on world