Return combo box choices as a parameters in wxpython

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Return combo box choices as a parameters in wxpython

anil

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/

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Return combo box choices as a parameters in wxpython

Andrea Gavana
Hi,

On Tue, 10 Jul 2018 at 16.52, anil <[hidden email]> wrote:

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.








--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Return combo box choices as a parameters in wxpython

Tim Roberts
In reply to this post by anil
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, [hidden email]
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.