문제

I have a small wxpython app which contains a CheckListBox. I have a counter below the box which I would like to be updated as items are checked.

Is this possible? A simplified version of my code is below.

Thanks Gavin

#!/usr/bin/env python

import wx
import os
import re
import glob

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self,parent, title=title, size=(750,300),                style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)
        self.panel = wx.Panel(self,-1)

        testlist = ["apples","dogs","cats","pears","blue"]

        self.listBox = wx.CheckListBox(self.panel, -1, (20, 6), (220, 195), testlist, wx.LB_SINGLE)

        self.filecount = self.listBox.GetCount()
        self.findchecked = self.listBox.GetChecked()


        self.filecountdisplay = str(len(self.findchecked)) + "/" + str(self.filecount) + " Files"
        self.inlistDisplay = wx.StaticText(self.panel, -1, self.filecountdisplay,(160,215))

        self.Centre()
        self.Show(True)



    def OnExit(self,e):
        self.Close(True)

app = wx.App(True)
frame = MyFrame(None,"Alexa Puller v1.1")
app.MainLoop()
도움이 되었습니까?

해결책

connect wx.EVT_PAINT with method that refreshes your filecount

    self.listBox.Bind(wx.EVT_PAINT, self.on_list_update)

def on_list_update(self, event):
    event.Skip()
    self.findchecked = self.listBox.GetChecked()
    self.filecount = self.listBox.GetCount()
    self.filecountdisplay = str(len(self.findchecked)) + "/" + str(self.filecount) + " Files"
    self.inlistDisplay = wx.StaticText(self.panel, -1, self.filecountdisplay,(160,215))
    self.Refresh()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top