I am having a great amount of difficulty understanding events for wxPython and have read many tutorials and other things so I was wondering if you could try to help me understand. First of all I am using Boa-Constructor so practially all of my code so far is autogenerated. What i want to do is choose from one of two option using a wx.Choice that i set up in BOA and i want for each of those two options a different function to be performed when i click on a standard button. The problem is that I dont understnad the event handling neccessary to retrieve the value in the wx.Choice and then execute code on the button click. Any help is appreciated.


Yes i agree i am also having a hard time understanding wxpython it's very complex and there isn't much documentation for it! however gui events are very simple! each window has a que for events and it process them in order.. when the window does nothing then it's event handler is receving NOP's ( do nothing messages) when it does not recive any messages it goes blank as happends alot of times! Now when it recives a command i distory it will do what it's programmed to do! ( some times you can prevent a window from closing by messging with the exit handeler")

For me using Boa is simply too frustrating. I rather create a template and use that to flesh out into a program. Here is a template that does something similar to what you want, experiment with it.

# the wxChoice() widget, a simple dropdown box
# select a color choice by clicking on it
# press button to display selected color in the title bar
import wx
class Frame1(wx.Frame):
    """ class MyFrame inherits wxFrame, uses default ID of -1"""
    def __init__(self ):
        wx.Frame.__init__(self, None, -1, 'wxChoice test', size=(300, 150))
        colorList = ['red', 'green', 'blue', 'yellow','white']
        # create the dropdown box
        self.choice1 = wx.Choice(self, -1, choices=colorList, pos=(15, 3))
        # select item 1 = 'green' to show
        # event handler for the choice box click
        self.choice1.Bind(wx.EVT_CHOICE, self.choice1_click)
        self.button1 = wx.Button(self, -1, label='Press Me', pos=(180, 3))
        # event handler for the button click
        self.button1.Bind(wx.EVT_BUTTON, self.button1_click)
    def choice1_click(self, event):
        """get the selected color choice"""
        self.color = self.choice1.GetStringSelection()
    def button1_click(self, event):
        """display the selected color choice"""
        self.SetTitle('You selected %s' % self.color)  # test
app = wx.PySimpleApp()
# create instance of class Frame1
frame1 = Frame1()
# show the frame
# start the event loop

Your observations is correct, wxPython has rather poor docs, particularly for beginners.

For me using Boa is simply too frustrating.

Good to know. I was just about to start learning wxPython ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.