StackWorld#
StackWorld visualizes a LIFO stack as a column of boxes growing upward.
The topmost box is highlighted in red to indicate the top-of-stack.
Operations#
Method |
Description |
|---|---|
|
Push a value onto the top. Raises |
|
Remove and return the top value. Raises |
|
Return the top value without removing it. Raises |
|
Return all current elements, bottom-to-top order. |
|
Return |
|
Return |
|
Remove all elements. |
|
Number of elements currently on the stack (property). |
Constructor parameters#
Parameter |
Default |
Description |
|---|---|---|
|
|
Maximum number of elements. |
|
|
Width of each element box in pixels. |
|
|
Height of each element box in pixels. |
|
|
Margin around the stack in pixels. |
|
light grey |
Background fill color. |
Example#
from miniworlds_data import StackWorld
world = StackWorld(capacity=5)
world.push("A")
world.push("B")
world.push("C")
print(world.peek()) # "C"
print(world.pop()) # "C"
world.run()