How do I get buttons with a scroll bar

Open
#1,759 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
cli

Research direction

Reproduce the provided full-screen example with the repeated pets list and the HSplit, VSplit, Window, Button, and Layout entry points shown. Check how oversized content is handled and determine the intended scrollbar behavior; done means the full button list remains navigable without the “Window is too small” failure while the result pane still works.

Written by the indexing model from the issue text.

Description

so I have this code

from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous
from prompt_toolkit.layout.containers import VSplit, HSplit, Window
from prompt_toolkit.layout.controls import FormattedTextControl
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.widgets import Button
from prompt_toolkit.layout import Layout
from prompt_toolkit import Application
from functools import partial

pets = ['dog', 'cat', 'parrot']
buttons = []

kb = KeyBindings()


@kb.add('c-c')
def exit_(event):
    event.app.exit()
    sys.exit()

kb.add("tab")(focus_next)
kb.add("s-tab")(focus_previous)

formatted_text = FormattedTextControl("")

for pet in pets:
    def handler(pet_name):
        formatted_text.text = f'{pet_name} button clicked!'

    btn = Button(pet, width=len(pet), handler=partial(handler, pet), left_symbol='', right_symbol='')
    buttons.append(btn)


root_container = VSplit(
        [
            HSplit(buttons),
            Window(width=1, char="|"),
            Window(formatted_text)

        ],
        padding=1
)


layout = Layout(root_container)
application = Application(layout=layout, key_bindings=kb, full_screen=True, mouse_support=True,)


application.run()

my problem is if I make the list bigger like pets = ['dog', 'cat', 'parrot']*100 it fails and gives "Window is too small". So I want to add a scrollbar next to it which allows me to scroll through the buttons, how do I do that?

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prompt-toolkit/python-prompt-toolkit

All issues in prompt-toolkit/python-prompt-toolkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.