我是Python和wxpython的新手。我试着写一个代码,我必须根据Combobox的用户输入创建Checkbox。我能够做到。但是当我更改选择时,旧的复选框仍然存在,我无法找到销毁它们或刷新的方法。任何帮助将受到高度赞赏。 这是我的代码:
import wx
class Form1(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
wx.EVT_COMBOBOX(self, 30, self.EvtComboBox)
self.lblhear = wx.StaticText(self,-1,"APPLICATION",wx.Point(30, 295))
self.lblhear3 = wx.StaticText(self, -1, "TASKS TO BE DONE", wx.Point(30, 370))
self.sampleList = ['ABC', 'PQR']
self.edithear=wx.ComboBox(self, 30, "",
wx.Point(110, 290), wx.Size(95, -1),
self.sampleList, wx.CB_DROPDOWN)
self.Bind(wx.EVT_COMBOBOX, self.AppSelect, self.edithear)
def AppSelect(self, event):
if event.GetString() == "ABC":
self.Application = 'ABC'
self.cb_list = []
act_list = ['Task1','Task2']
elif event.GetString() == "PQR":
self.Application = 'PQR'
self.cb_list = []
act_list = ['Task3','Task4']
pos_y = 380
id_cb = 100
for i in act_list:
pos_y += 20
id_cb += 20
self.cb = wx.CheckBox(self, id_cb, label=i, pos=(50, pos_y))
self.cb.SetValue(False)
self.cb_list.append(self.cb)
def EvtComboBox(self, event):
if event.GetId() == 30:
self.Application = self.event.GetString()
app = wx.PySimpleApp()
frame = wx.Frame(None, size=(1200,800))
Form1(frame)
frame.Show(1)
app.MainLoop()
答案 0 :(得分:1)
您可以通过调用Destroy
方法来销毁现有的复选框小部件。也许是这样的:
for cb in self.cb_list:
cb.Destroy()