wxPython:如何正确选择 ListCtrl 项目?

gri*_*yvp 2 python wxwidgets wxpython

我的 Windows 8 上安装了带有 wxWidgets 2.8.11.0 的 python 2.7。如果我执行以下代码:

import wx

app = wx.App( redirect = False )
wnd = wx.Frame( parent = None )
widget = wx.ListCtrl( parent = wnd, style = wx.LC_REPORT )
widget.InsertColumn( 0, "items" )
widget.InsertStringItem( 0, "foo" )
widget.InsertStringItem( 1, "bar" )
widget.InsertStringItem( 2, "baz" )
widget.Select( 1 )
wnd.Show()
app.MainLoop()
Run Code Online (Sandbox Code Playgroud)

我看到了一个包含 3 个项目列表的窗口,第二个被选中。但是如果我按“向下”键 -选择了第一项!是否可以选择项目,因此按“向上”和“向下”键将移动现有选择并且不会跳到第一个项目?

joa*_*uin 5

同时使用Select(突出显示)和Focus(使该行成为当前行):

........
widget.Focus(1)
widget.Select(1)
..........
Run Code Online (Sandbox Code Playgroud)