#1
  1. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,350
    Rep Power
    630

    wxpython Enable/Disable Buttons


    I have the following button defined:
    Code:
    self.saveBtn=wx.Button(pnl,ID_SAVE,'Save')
    self.saveBtn.Bind(wx.EVT_BUTTON,self.OnSave)
    self.saveBtn.Disable()
    Then I set up a TextCtrl, bound to a method that SHOULD enable the button:
    Code:
    self.rampTemp=wx.TextCtrl(pnl,-1,self.temps[i],size=(40,-1))
    self.rampTemp.Bind(wx.EVT_CHAR,self.OnRampChar())
    Finally in the event handler I enable the button:
    Code:
      def OnRampChar(self):
            self.saveBtn.Enable()
    Unfortunately the button is not enabled so I must be missing something. Can anyone see what that is? TIA.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,350
    Rep Power
    630
    I found at least part of the problem but I don't know why it is happening. In the code that sets up the TextCtrl, I add default values to the fields. That triggers the event and runs OnRampChar. Later I disable the button. Once I show the panel and enter date into the field, the event is not triggered.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    653
    Rep Power
    39
    You are calling the function when you define the callback (note the parens), instead of sending a reference to the function object to be called when to button is pressed.
    Code:
    self.rampTemp.Bind(wx.EVT_CHAR,self.OnRampChar())
    ##
    ## should be
    self.rampTemp.Bind(wx.EVT_CHAR,self.OnRampChar) <-- no parens

    Comments on this post

    • gw1500se agrees : Good catch
    Last edited by dwblas; May 14th, 2016 at 03:38 PM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,350
    Rep Power
    630
    Wow, subtle. Why didn't Bind flag an error for the wrong type or object? It works now, thanks.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    653
    Rep Power
    39
    None of the GUI toolkits flag that as an error. It should be a warning at least.

IMN logo majestic logo threadwatch logo seochat tools logo