Return combo box choices as a parameters in wxpython

i am working on following piece of code. i want to return combo box choices
as parameters and use in another function. As combo box comes up with event
handler i don't find an easy way to call it in another function. my code
looks like following

self.combo_box_product = wx.ComboBox(self.panel_1, wx.ID_ANY,
choices=["one", "two", "three", "OTHERS"], style=wx.CB_DROPDOWN |
wx.CB_READONLY | wx.TE_PROCESS_ENTER)
self.Bind(wx.EVT_COMBOBOX, self.OnCombo, self.combo_box_product)

def OnCombo(self, event):
    product = self.combo_box_product.GetValue()
    return product
    event.Skip()

and i want to call in another function as below:

def func(self):
    x=self.OnCombo()
    y=x
but as you already guess mistake is OnCombo() misses argument and program
outputs error Can someone help me, how to dealt with it

Thanks

···

--
Sent from: http://wxpython-users.1045709.n5.nabble.com/

Hi,

i am working on following piece of code. i want to return combo box choices

as parameters and use in another function. As combo box comes up with event

handler i don’t find an easy way to call it in another function. my code

looks like following

self.combo_box_product = wx.ComboBox(self.panel_1, wx.ID_ANY,

choices=[“one”, “two”, “three”, “OTHERS”], style=wx.CB_DROPDOWN |

wx.CB_READONLY | wx.TE_PROCESS_ENTER)

self.Bind(wx.EVT_COMBOBOX, self.OnCombo, self.combo_box_product)

def OnCombo(self, event):

product = self.combo_box_product.GetValue()

return product

event.Skip()

and i want to call in another function as below:

def func(self):

x=self.OnCombo()

y=x

but as you already guess mistake is OnCombo() misses argument and program

outputs error Can someone help me, how to dealt with it

Thanks

Maybe something like this:

def OnCombo(self, event=None):
product = self.combo_box_product.GetValue()

 If event is not None:
    event.Skip()

return product

Sorry, typing on the phone…

Andrea.

···

On Tue, 10 Jul 2018 at 16.52, anil anil.ftdpl@gmail.com wrote:

Sent from: http://wxpython-users.1045709.n5.nabble.com/

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

anil wrote:

def OnCombo(self, event):
    product = self.combo_box_product.GetValue()
    return product
    event.Skip()

That won't work, of course, because you are returning before you do the
event.Skip(). Was that a cut-and-paste problem?

and i want to call in another function as below:

def func(self):
    x=self.OnCombo()
    y=x
but as you already guess mistake is OnCombo() misses argument and program
outputs error Can someone help me, how to dealt with it

Andrea's suggestion is a good one, but another alternative is to
separate the action from the event:

def getValue\(self\):
    product = self\.combo\_box\_product\.GetValue\(\)
    return product

def OnCombo\(self, event\):
    event\.Skip\(\)
    return self\.getValue\(\)

def func\(self\):
    x = self\.getValue\(\)
    y = x
···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.