【问题标题】:Wxpython ScrollBarWxpython 滚动条
【发布时间】:2020-04-28 21:23:40
【问题描述】:

我希望我的 wx.ListCtrl 的 ScrollBar 会在新项目添加到列表并且 ScrollBar 变长时自动下降。 这就是我创建 wx.ListCtrl

的方式
import wx

app = wx.App()
frame = wx.Frame(None, -1, title='2', pos=(0, 0), size=(500, 500))
frame.Show(True)
app.SetTopWindow(frame)
message_list = wx.ListCtrl(frame, size=(200, 200), pos=(0, 0),
                       style=wx.LC_REPORT | wx.BORDER_SUNKEN)
message_list.InsertColumn(0, 'Chat: ', width=150)
for i in range(15):
   message_list.InsertItem(i, "name" + str(i))

### I want that after this loop, the scroll bar will be at the end of the list (Name 14)

app.MainLoop()

【问题讨论】:

    标签: python python-3.x wxpython listctrl


    【解决方案1】:

    选择(self, idx, on=1)
    选择/取消选择一个项目。
    & EnsureVisible(n) 确保所选项目可见,即它滚动列表控件。

    所以这会起作用:

    import wx
    
    app = wx.App()
    frame = wx.Frame(None, -1, title='2', pos=(0, 0), size=(500, 500))
    frame.Show(True)
    app.SetTopWindow(frame)
    message_list = wx.ListCtrl(frame, size=(200, 200), pos=(0, 0),
                                style=wx.LC_REPORT | wx.BORDER_SUNKEN)
    message_list.InsertColumn(0, 'Chat: ', width=150)
    for i in range(30):
        message_list.InsertItem(i, "name" + str(i))
    
    msg_endpoint = message_list.GetItemCount() - 1
    message_list.Select(msg_endpoint,1)    #Select last item
    message_list.EnsureVisible(msg_endpoint)
    ### I want that after this loop, the scroll bar will be at the end of the list (Name 14)
    
    app.MainLoop()
    

    注意:使用message_list.Select(i,0) 取消选择项目(i)
    滚动条仅在需要时才可见。

    【讨论】:

    • 我试过了,没用。 ScrollBar 仍然保持在列表的顶部。
    • 我的错误,我误读了这个问题,完全错过了它的滚动条部分。我假设您出于某种原因想要选择项目。一定是脑残!编辑后的答案至少应该解决问题,如果没有让您满意的话。
    猜你喜欢
    • 2011-08-20
    • 1970-01-01
    • 2021-04-04
    • 1970-01-01
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    • 2013-12-19
    相关资源
    最近更新 更多