layers style allows you to define an ordered set of layers.
layers style accepts one or more
<name> that define the layers that the widget is aware of, and the order in which they will be painted on the screen.
The values used here can later be referenced using the
The layers defined first in the list are drawn under the layers that are defined later in the list.
More information on layers can be found in the guide.
In the example below,
#box1 is yielded before
#box1 is on the higher layer, it is drawn on top of
from textual.app import App, ComposeResult from textual.widgets import Static class LayersExample(App): CSS_PATH = "layers.css" def compose(self) -> ComposeResult: yield Static("box1 (layer = above)", id="box1") yield Static("box2 (layer = below)", id="box2") if __name__ == "__main__": app = LayersExample() app.run()
# Bottom layer is called 'below', layer above it is called 'above' widget.style.layers = ("below", "above")
- The layout guide section on layers.
layerto set the layer a widget belongs to.