Reputation: 1
I am a novice in Python and wxpython. I tried to write a code ,in which I have to create Checkboxes based on the user input of a Combobox. I am able to do it. But when I am changing the selections , the old Checkboxes are still there and I am unable to find a way to destroy them or refresh. Any help would be highly appreciated. Here is my code :
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()
Upvotes: 0
Views: 327
Reputation: 6206
You can destroy the existing checkbox widgets by calling their Destroy
method. Perhaps something like this:
for cb in self.cb_list:
cb.Destroy()
Upvotes: 1