您好我正在尝试实现一个GUI,其中选中/取消选中1个标题为" ALL"的复选框。将选中/取消选中其余复选框。但是这段代码不起作用,我似乎无法找出原因。这是我的代码:
import wx
import calendar,datetime
import os
class MainFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, "", size = (500, 800))
panel = wx.Panel(self, -1)
labelGetTime = wx.StaticText(panel, -1, "Select Time Duration")
labelGetArea = wx.StaticText(panel, -1, "Select Area")
labelStart = wx.StaticText(panel, -1, "Start")
self.startCal = wx.DatePickerCtrl(panel, style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
labelEnd = wx.StaticText(panel, -1, "End")
self.endCal = wx.DatePickerCtrl(panel, style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
retrieveBtn = wx.Button(panel, -1, "Retrieve Data")
getStatBtn = wx.Button(panel, -1, "Get Statistics")
getGraphBtn = wx.Button(panel, -1, "Plot Graph")
#self.Bind(wx.EVT_BUTTON, self.OnClickGetDay, retrieveBtn)
#self.Bind(panel, self.OnSet, getStatBtn)
#self.Bind(panel, self.OnSet, getGraphBtn)
self.cb_list = []
self.selAllCB = wx.CheckBox(panel, -1, "ALL")
self.cb_list.append(wx.CheckBox(panel, -1, "Area1"))
self.cb_list.append(wx.CheckBox(panel, -1, "Area2"))
self.cb_list.append(wx.CheckBox(panel, -1, "Area3"))
self.cb_list.append(wx.CheckBox(panel, -1, "Area4"))
self.Bind(wx.EVT_CHECKBOX, self.OnSelect, self.selAllCB)
box = wx.BoxSizer(wx.VERTICAL)
timeBox = wx.BoxSizer(wx.HORIZONTAL)
areaBox = wx.BoxSizer(wx.HORIZONTAL)
getTimeBox = wx.BoxSizer(wx.VERTICAL)
getAreaBox = wx.BoxSizer(wx.VERTICAL)
btnBox = wx.BoxSizer(wx.VERTICAL)
staBox = wx.BoxSizer(wx.HORIZONTAL)
endBox = wx.BoxSizer(wx.HORIZONTAL)
box.Add(labelGetTime, 1, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)
box.Add(timeBox, 4, wx.ALL, 5)
box.Add(labelGetArea, 1, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)
box.Add(areaBox, 6, wx.ALL, 5)
timeBox.Add(getTimeBox, 3, wx.ALL, 5)
timeBox.Add(retrieveBtn, 1, wx.ALIGN_CENTER)
areaBox.Add(getAreaBox, 3, wx.ALL, 5)
areaBox.Add(btnBox, 1, wx.ALIGN_CENTER)
getTimeBox.Add(staBox, 1, wx.ALL|wx.EXPAND, 5)
getTimeBox.Add(endBox, 1, wx.ALL|wx.EXPAND, 5)
getAreaBox.Add(self.selAllCB, 1, wx.ALL|wx.ALIGN_CENTER, 5)
getAreaBox.Add(self.cb_list[0], 1,wx.ALL| wx.ALIGN_CENTER, 5)
getAreaBox.Add(self.cb_list[1], 1,wx.ALL| wx.ALIGN_CENTER, 5)
getAreaBox.Add(self.cb_list[2], 1,wx.ALL| wx.ALIGN_CENTER, 5)
getAreaBox.Add(self.cb_list[3], 1,wx.ALL| wx.ALIGN_CENTER, 5)
btnBox.Add(getStatBtn, 1, wx.ALIGN_CENTER|wx.BOTTOM , 8)
btnBox.Add(getGraphBtn, 1, wx.ALIGN_CENTER|wx.TOP, 8)
staBox.Add(labelStart, 1, wx.ALL, 5)
staBox.Add(self.startCal, 4, wx.ALL)
endBox.Add(labelEnd, 1, wx.ALL, 5)
endBox.Add(self.endCal, 4, wx.ALL)
panel.SetSizer(box)
box.Fit(self)
def OnSelect(self):
for cb in self.cb_list:
cb.SetValue(self.selAllCB.GetValue())
class MyApp(wx.App):
def OnInit(self): #wxWindows calls this method to initialize the application
frame = MainFrame(None, -1) #Create an instance of MainFrame class
frame.Show()
self.SetTopWindow(frame) #Tell wxWindows that this is main window
return True #Success flag
app = MyApp()
app.MainLoop()
答案 0 :(得分:0)
你的OnSelect(自我)应该是:
def OnSelect(self, evt):
您应该始终在控制台上阅读程序的输出。