让我们以calculator.py为例
要添加与鼠标滚轮配合使用的滚动条,您需要更改:
output_field = TextArea(style="class:output-field", text=help_text)
致:
output_field = TextArea(style="class:output-field", text=help_text, scrollbar=True)
但是,您会添加或更改什么来使用page up(向上翻页)和page down(向下翻页)键滚动文本区域
# The key bindings.
kb = KeyBindings()
@kb.add("pageup")
def _(event):
# What goes here?
pass
@kb.add("pagedown")
def _(event):
# What goes here?
pass
改变焦点
最简单的方法可能是导入
focus_next
(或focus_previous
)并将其绑定到控制空间(或其他任何内容)
集中注意力
您还可以将注意力集中在
input_field
,导入scroll_page_up
和scroll_page_down
然后将焦点切换到
output_field
,调用scroll_page_up
/scroll_page_down
,最后将焦点切换回input_field
相关问题 更多 >
编程相关推荐