Detecting the scroll bar visibility in a container? #3949
-
By default, container doesn't show the scrollbar unless the contents inside container are longer or bigger than container. Is there anyway to detect that once scroll bar appears on screen? Currently i'm doing this way def move_down():
if mycontainer.vertical_scrollbar.styles.visibility == "visible":
# scroll bar has appeared, do something but this one it always give me "visible" even no scroll bar appeared on screen?. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
The |
Beta Was this translation helpful? Give feedback.
-
Bit late to this party, but if I'm reading the question correctly, it's how to detect when one or both of the scrollbars appear? If so keep in mind that from textual import on
from textual.app import App, ComposeResult
from textual.containers import VerticalScroll
from textual.widgets import Button, Label
class MaybeFocus(VerticalScroll, can_focus=False):
def watch_show_vertical_scrollbar(self) -> None:
self.can_focus = self.show_horizontal_scrollbar or self.show_vertical_scrollbar
def watch_show_horizontal_scrollbar(self) -> None:
self.can_focus = self.show_horizontal_scrollbar or self.show_vertical_scrollbar
class FocusWhenScrollApp(App[None]):
CSS = """
Label {
height: 5;
background: red;
width: 1fr;
}
"""
def compose(self) -> ComposeResult:
yield Button("MORE!")
yield MaybeFocus()
@on(Button.Pressed)
def more(self) -> None:
self.query_one(MaybeFocus).mount(Label("Stuff"))
if __name__ == "__main__":
FocusWhenScrollApp().run() |
Beta Was this translation helpful? Give feedback.
Are you sure that the scrollbar is appearing on your container and not another parent container or the screen?
For example, this seems to work after a quick test: