Let's use calculator.py for example.
To add a scrollbar that works with the mouse wheel, you would change:
output_field = TextArea(style="class:output-field", text=help_text)
to:
output_field = TextArea(style="class:output-field", text=help_text, scrollbar=True)
But what would you add or change to scroll the TextArea
with the page up and page down keys?
# The key bindings.
kb = KeyBindings()
@kb.add("pageup")
def _(event):
# What goes here?
pass
@kb.add("pagedown")
def _(event):
# What goes here?
pass
Change focus
The simplest way would probably be to import
focus_next
(orfocus_previous
)and bind it to Control-Space (or anything else).
Keep focus
You could also, to seemingly keep the focus on
input_field
, importscroll_page_up
andscroll_page_down
then switch focus to
output_field
, callscroll_page_up
/scroll_page_down
and finally change focus back toinput_field
.