wxPython combobox execution at 'apply'

Hi,

···

On Thursday, April 25, 2013 8:52:36 AM UTC-5, Ibraheem Khan wrote:

Hi,

I am using two combobox on a single frame and running into a problem. Whenever i select an option from combobox1 then the associated processes are executed instead of waiting for me to finish selecting option from combobox2 and press ‘apply’ button. Please suggest where things are going out of control. Thanks!
Following is code snippet:

class ComboBoxFrame(wx.Frame):

def init(self):

wx.Frame.init(self, None, -1, ‘Input Data Selection’, size=(350, 300))

self.Bind(wx.EVT_CLOSE, self.OnClose)

panel = wx.Panel(self, -1)

wx.StaticText(panel, -1, “Select Soil Data”, (15, 15))

SoilList = [soil1’, ‘soil2’, ‘soil3’]

self.Soil = wx.ComboBox(panel, -1, “”, (15, 30), wx.DefaultSize,SoilList, wx.CB_DROPDOWN)

self.Soil.Bind(wx.EVT_COMBOBOX, self.OnSelect, self.Soil)

wx.StaticText(panel, -1, “Select Hyd Condition”, (15, 15))

HydList = [‘h1’, ‘h2’, ‘h3’]

self.Hyd = wx.ComboBox(panel, -1, “”, (15, 30), wx.DefaultSize,HydList, wx.CB_DROPDOWN)

self.Hyd.Bind(wx.EVT_COMBOBOX, self.OnSelect, self.Hyd)

self.btnApply = wx.Button(panel, label=“Apply”, pos=(65, 200))

self.Bind(wx.EVT_BUTTON, self.OnClose, id=self.btnApply.GetId())

self.Show(True)

def OnClose(self, event):

self.Show(False)

def OnSelect(self, event):

soil = str(self.Soil.GetValue())

do_something_…

If you don’t want the ComboBox to do something when you select an item from it, then don’t bind it to an EVT_COMBOBOX. This tells wx to call a method any time you choose something in the combo box.

  • Mike