Managing events

cantabile cantabile.03 at wanadoo.fr
Sat Sep 3 13:03:33 EDT 2005


Hi,

I have a class (a gui) with buttons and other controls. A button, for 
example, has a callback method, so that writing

    b = Button(label, OnClick)

will call the global OnClick method.

Now, if I want the OnClick method to call some of my main class methods, 
I need to write:

     UI = None
     ...
     class MainClass:
         ...
         global UI = self


Then,
def OnClik(button):
    UI.do_something(button.get_label())

Is this the correct way to do it in Python ? Isn't there a potential 
flaw in declaring my MainClass instance as a global variable ?



More information about the Python-list mailing list