Skip to content

ScrollView

ScrollView is a scrollable container for arbitrary widgets.

It provides a framed content area inside a scrolling viewport, handling scrollbars, mousewheel behavior, and sizing so you can build scrollable panels and forms without manually wiring a Canvas + scrollbars.


Quick start

import bootstack as bs

app = bs.App()

sv = bs.ScrollView(app)
sv.pack(fill="both", expand=True, padx=20, pady=20)

# Get the content frame and add widgets to it
content = sv.add()
for i in range(30):
    bs.Label(content, text=f"Row {i+1}").pack(anchor="w", pady=4)

app.mainloop()

When to use

Use ScrollView when:

  • you need to scroll a region that contains normal widgets (forms/panels/cards)

  • you want to scroll long forms, settings panels, or stacked content

  • you want to build resizable layouts where only part of the UI scrolls

  • you want to avoid manual Canvas/Scrollbar plumbing

Consider a different control when:

  • you need a multi-line text editor/log output -- use ScrolledText

  • you need highly customized scrolling or virtualized rendering -- use manual Canvas + Scrollbar


Appearance

ScrollView is different from ScrolledText:

  • ScrollView scrolls widgets

  • ScrolledText scrolls text content (tk.Text)


Examples & patterns

Adding content

Use add() to get a content frame for placing widgets.

sv = bs.ScrollView(app)
sv.pack(fill="both", expand=True)

content = sv.add()  # Returns a Frame
for i in range(30):
    bs.Label(content, text=f"Item {i+1}").pack(anchor="w", pady=4)

Frame options (padding, color, etc.) can be passed directly:

content = sv.add(padding=10, accent="primary")

Calling add() multiple times returns the same frame (idempotent).

Custom content widget

You can also pass your own widget to add():

my_frame = bs.Frame(sv.canvas, padding=16)
sv.add(my_frame)

bs.Label(my_frame, text="Custom frame with padding").pack()

Scroll direction

Choose vertical, horizontal, or both scrolling depending on content.

bs.ScrollView(app, scroll_direction='vertical')    # default
bs.ScrollView(app, scroll_direction='horizontal')
bs.ScrollView(app, scroll_direction='both')

Scrollbar visibility

Use auto-hide policies to keep UI clean.

bs.ScrollView(app, scrollbar_visibility='always')    # default
bs.ScrollView(app, scrollbar_visibility='never')     # hidden but scrolling works
bs.ScrollView(app, scrollbar_visibility='hover')     # appear on mouse enter
bs.ScrollView(app, scrollbar_visibility='scroll')    # appear when scrolling

Padding

Add padding to your content frame:

content = sv.add()
inner = bs.Frame(content, padding=16)
inner.pack(fill="both", expand=True)

for i in range(20):
    bs.Label(inner, text=f"Item {i+1}").pack(anchor="w", pady=4)

Behavior

  • Mouse wheel scrolling is handled for cross-platform consistency.

  • The scroll region updates as content size changes.

  • Use fill="both", expand=True to let the viewport grow with the window.


Additional resources

  • Scrollbar -- low-level scrollbar primitive

  • ScrolledText -- scrollable text widget

  • Frame -- common content container inside a scroll view

Framework concepts

API reference