Toolbar
Toolbar¶
- class miniworldmaker.containers.toolbar.Toolbar[source]¶
A Toolbar contains widgets (Buttons, Labels, …)
Public Data Attributes:
Background color as Tuple, e.g.
Defines left margin
Defines right margin
Defines top margin
Inherited from : py: class:Container
container_width
container_height
window
size
rect
window_docking_position
width
height
Public Methods:
__init__
()Base class for toolbars.
add_widget
(widget[, key])Adds a widget to the toolbar
remove_widget
(item)Removes a widget from the toolbar.
has_widget
(key)Checks if self.widgets has key
get_widget
(key)Gets widget by key
repaint
()Implemented in subclasses
- rtype:
get_event
(event, data)Implemented in subclasses
update
()Implemented in subclasses
send_message
(text)Inherited from : py: class:Container
__init__
()Base class for toolbars.
update_width_and_height
()repaint
()Implemented in subclasses
blit_surface_to_window_surface
()remove
()Implemented in subclasses
handle_event
(event, data)get_event
(event, data)Implemented in subclasses
is_in_container
(x, y)- rtype:
position_is_in_container
(pos)- rtype:
update
()Implemented in subclasses
get_local_position
(position)- rtype:
Private Methods:
_paint_widgets
()_widgets_total_height
()_set_widget_width
(widget)Inherited from : py: class:Container
_add_to_window
(app, dock[, size])
- __init__()[source]¶
Base class for toolbars.
Example
Add a Toolbar which interacts with Tokens on board via messages:
from miniworldmaker import * board = Board() board.add_background("images/galaxy.jpg") toolbar = Toolbar() button = Button("Start Rocket") toolbar.add_widget(button) board.add_container(toolbar, "right") @board.register def on_message(self, message): if message == "Start Rocket": rocket.started = True rocket = Token(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_board(self): self.remove() board.run()
- add_widget(widget, key=None)[source]¶
Adds a widget to the toolbar
- Parameters:
widget – The Widget
key – A unique key
- Returns:
_description_
- Return type:
- Return type:
- property background_color¶
Background color as Tuple, e.g. (255,255,255) for white
- property first¶
- property margin_left¶
Defines left margin
- property margin_right¶
Defines right margin
- property margin_top¶
Defines top margin
- property pagination¶