wx.Python CheckListBox更新计数器

时间:2013-05-27 10:46:57

标签: wxpython refresh checklistbox

我有一个小的wxpython应用程序,其中包含一个CheckListBox。 我在框下方有一个计数器,我希望在检查项目时更新。

这可能吗? 我的代码的简化版本如下。

由于 加文

#!/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()

1 个答案:

答案 0 :(得分:1)

使用刷新文件计数的方法连接wx.EVT_PAINT

    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()