大家晚上好,
我有一个使用Python Urwid库构建的应用程序。它有几个字段,因此使用"Page Down“或"Down”键转到应用程序的底部需要相当长的时间。我只是想知道是否有直接将光标移到底部的按键操作。类似于下面的内容:
class SimulationView(urwid.WidgetWrap): (line 6)
{
def get_main_frame(self): (line 127)
buttons_box = urwid.ListBox(buttons_walker) (line 148)
errors_box = urwid.ListBox(self.errors_content) (line 155)
sim_listbox = urwid.ListBox(self.sim_list_content)(line 158)
body = urwid.Pile([(6, buttons_box),('weight', 4, sim_listbox),
('weight', 1, errors_box)])
frame = urwid.Frame(body, header=header)
return frame
def keypress(self, size, key):
If key is "a":
# command to take the cursor to the bottom of the application
}提前谢谢。
发布于 2018-03-27 01:50:03
对于默认的窗口小部件,似乎没有任何对应的映射,只是因为每个应用程序可能对“底部”有不同的概念。
你说的“底部”到底是什么意思?有没有一个小部件总是在那里,你想让它成为焦点?
container widgets具有一个可写focus_position属性,您可以使用该属性来更改焦点,下面是一个示例:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, absolute_import, division
import urwid
def global_input(key):
if key in ('q', 'Q', 'esc'):
raise urwid.ExitMainLoop()
elif key == 'page down':
# "bottom" is last button, which is before footer
pile.focus_position = len(pile.contents) - 2
elif key == 'page up':
# "top" is the first button, which is after footer
pile.focus_position = 1
elif key in ('1', '2', '3', '4'):
pile.focus_position = int(key)
if __name__ == '__main__':
footer = urwid.Text('Footer')
pile = urwid.Pile([
urwid.Padding(urwid.Text('Header'), 'center', width=('relative', 6)),
urwid.Button('Button 1'),
urwid.Button('Button 2'),
urwid.Button('Button 3'),
urwid.Button('Button 4'),
urwid.Padding(footer, 'center', width=('relative', 20)),
])
widget = urwid.Filler(pile, 'top')
loop = urwid.MainLoop(widget, unhandled_input=global_input)
loop.run()https://stackoverflow.com/questions/49495437
复制相似问题