wxPython problems

F. GEIGER fgeiger at datec.at
Fri Mar 28 07:32:52 EST 2003


> I am quite new to wxPython and would like to ask that is it possible to
run
> multiple functions when you for example press a button? I think that the
> answer is very simple, but I just did not found it anywhere.

def OnButton(self, event):
   myFunction()
   myObject = MyClass()
   myObject.doThis()
   myObject.DoThat()
   return

You have to set the above method as the handler of the button you wish to
react this way. Assuming your button is self._ctrlButton, this will read:

EVT_BUTTON(self, self._ctrlButton.GetId(), self.OnButton)

> Second question: when a function is processed how can you use *if*
statement
> in it so that if a certain variable is (for example) 5 then the function
> runs another function? Or is there any sense to do so?

def OnButton(self, event):
   if someValue == 5:
      return self._mine.itsValue()
   else:
      return self._yours.itsValue()

> One more question. How can you make a wxStaticText widget to monitor a
> certain variable so that if a variable changes the widget shows the new
> value?

The control, which has changed, tells the control, which has to display the
change. You could use a mediator object to do the communication.

def OnXXX(self, event):
   self._ctrlTheOtherOne.SetValue(theNewValueToBeDisplayed)
   return


Cheers
Franz







More information about the Python-list mailing list