2013-05-27 47 views
0

我有一個包含CheckListBox的小型wxpython應用程序。 我在箱子下面有一個櫃檯,我希望在檢查物品時進行更新。wx.Python 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

與刷新您的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() 
+0

這工作的感謝,雖然它似乎加上前一計頂部的更新方法連接wx.EVT_PAINT。 –

+0

但有點修補整理出來。非常感謝你的幫助 –