WX Problem

I’m having a problem creating a GUI. I’m trying to bind an event to a
button but when i bind the event, the callback is called immediately.
I’m not sure what the heck is happening. Any help would be greatly
appreciated. if you look at the code below you can see that the
callback is getting called immediately.

#Code Snippet

def _create_Gui (self, vbox):
    self.myform = myform = form.form()

    hbox = wx.BoxSizer(wx.HORIZONTAL)
    hbox.Add((5,0),0)

    self.b1 = wx.ToggleButton(self.panel,wx.ID_ANY,"button 1")
    print "1"
    self.b1.Bind(wx.EVT_LEFT_DCLICK, self._setText())
    print "2"
    hbox.Add(self.b1,1,wx.LEFT | wx.RIGHT ,2)

    self.b2 = wx.Button(self.panel,wx.ID_ANY,"button 2")
    hbox.Add(self.b2,1,wx.LEFT | wx.RIGHT ,2)
    vbox.Add(hbox, 0, wx.EXPAND)
    return

def _setText(self):
    print "button pressed"
    self.b1.Show(False)
    return

Terminal Window Output

1
button pressed
2

On Wed, Apr 22, 2009 at 10:54:12AM -0400, Matthew Dolloff wrote:

    hbox = wx.BoxSizer(wx.HORIZONTAL)
    hbox.Add((5,0),0)

    self.b1 = wx.ToggleButton(self.panel,wx.ID_ANY,"button 1")
    print "1"
    self.b1.Bind(wx.EVT_LEFT_DCLICK, self._setText())

self.setText() is a call, that’s why it’s getting called right away.
Try self.setText [no parens].

Yeah I figured that out just after I sent the email. Thanks for the
feedback though!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs