wxPython problems

Davor Cengija dcengija_remove_ at inet.hr
Fri Mar 28 13:38:21 CET 2003

Heikki Salo wrote:

> I am quite new to wxPython 

So am I, but I'll try to answer your questions.

> 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.

Have a function (method) which calls other methods.

EVT_BUTTON(self, id, self.OnClick)

def OnClick(self, event):

> 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?

If you have member variables, you simple refer to them, and if you want to 
read a certain value from some GUI element, say a text field, you need to 
get the refetence to that element and read its value.

def Process(self):
        if self.something == 5:
        # or
        field = self.FindWindowById(FIELD_ID)
        if field.GetValue() == "":

> Third question coming in. How can you run a function which is in another
> class? If I have the main class wich consists all widgets and few
> functions and a second class with many functions, how can the first class
> call (like when you press a button) functions from the second class? Or
> again, is there any sense in doing so?

This is rather basic OOP question. You need a handle (reference) to the 
object which has the needed methods, and simply call them. The problem is 
how to get that reference. Either create that object

t = Test(param)

or (you're probably looking for this) fetch the reference to that other 
object using FindWindowById.

> 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?

If that variable is the value from some other GUI element, you can register 
an event listener for that element, and in the called method update the 
wxStaticText's value. If that variable is 'independent', then you'll need 
some other kind of listerens. Unfortunatelly, I'm still learning python and 
don't know how to do that. 

Davor Cengija, dcengija_remove_ at inet.hr

More information about the Python-list mailing list