Question

j'ai un wx.ListCtrl qui a le wx.LC_REPORT Bit set. Il a 3 colonnes. Je veux que la première colonne soit remplie d'une case à cocher les uns pour les autres. J'ai essayé d'utiliser le ListCtrl.InsertItem Méthode, mais cela ne prend qu'un seul argument (info) Et je ne trouve aucun document sur ce que cet argument doit être. J'ai essayé de passer un wx.CheckBox à InsertItem en vain.

Est-il possible d'avoir une case à cocher comme entrée dans une listctrl wxpython? Si oui, comment pourrais-je faire cela?

Dans le cas où il y a une ambiguïté de ce dont je parle, voici une photo de ce que je veux (je ne sais pas si c'est WX, mais c'est ce que je recherche). Je veux les cases à côté de 1..5 dans la colonne n °.

list control with checkboxes

Était-ce utile?

La solution

Jettes un coup d'oeil à wx.lib.mixins.listctrl.

import wx
import wx.lib.mixins.listctrl as listmix

class TestListCtrl(wx.ListCtrl, listmix.CheckListCtrlMixin, listmix.ListCtrlAutoWidthMixin):
    def __init__(self, *args, **kwargs):
        wx.ListCtrl.__init__(self, *args, **kwargs)
        listmix.CheckListCtrlMixin.__init__(self)
        listmix.ListCtrlAutoWidthMixin.__init__(self)
        self.setResizeColumn(3)

    def OnCheckItem(self, index, flag):
        print(index, flag)

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.panel = wx.Panel(self)
        self.list = TestListCtrl(self.panel, style=wx.LC_REPORT)
        self.list.InsertColumn(0, "No.")
        self.list.InsertColumn(1, "Progress")
        self.list.InsertColumn(2, "Description")
        self.list.Arrange()
        for i in range(1, 6):
            self.list.Append([str(i), "", "It's the %d item" % (i)])        
        self.button = wx.Button(self.panel, label="Test")
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.list, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
        self.sizer.Add(self.button, flag=wx.EXPAND | wx.ALL, border=5)
        self.panel.SetSizerAndFit(self.sizer)
        self.Show()

app = wx.App(False)
win = MainWindow(None)
app.MainLoop()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top