Is it possible to make an accordion style check list in wxPython?

眉间皱痕 提交于 2020-01-16 06:57:10

问题


I want to make a checklist with a accordion style in a wxPython widget. I know about checklistbox, but I couldn't find anything in the official docs concerning it. Has anyone done this?


回答1:


You can use a wx.combo.ComboCtrl which allows any custom popup, and combine this with a wx.CheckListBox.

Here's what is could look like, folded:

and unfolded:

To get this, I started with the ComboCtrl example in the demo, and in the ListCtrlComboPopup list class I replaced ListCtrl with CheckListBox everywhere (and made a few other small changes to make the commands consistent with a CheckListBox control rather than a ListCtrl).




回答2:


You have to use a wx.PreCheckListBox() for the two part initialization that is required for this.

Here's my implementation. Combine this with a ComboCtrl and you're all set.

import wx
from wx import combo

class checkListComboPopup(combo.ComboPopup):

def __init__(self):
    combo.ComboPopup.__init__(self)
    self.checklist = wx.PreCheckListBox()
    self._value = -1

def Init(self):
    self._value = -1

def Create(self, parent):
    return self.checklist.Create(parent, 1, wx.Point(0,0), wx.DefaultSize)

def GetControl(self):
    return self.checklist

def SetStringValue(self, s):
    pass

def GetStringValue(self):
    if (self._value >= 0):
        return self.checklist.GetItemText(self, self._value)
    else:
        return wx.EmptyString

def OnMouseMove(self, event):
    pass

def GetPreCheckList(self):
    return self.checklist

def OnMouseClick(self, event):
    pass

Two part creation



来源:https://stackoverflow.com/questions/2906110/is-it-possible-to-make-an-accordion-style-check-list-in-wxpython

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!