cantabile wrote in news:[EMAIL PROTECTED] in comp.lang.python:
> 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 ? Try: class MainClass: def do_something( self, label ): pass def OnClick( self, button ): self.do_something( button.get_label() ) def some_method( self ): b = Button( label, self.OnClick ) With the above you could also do: main = MainClass() b = Button( "A Label", main.OnClick ) Rob. -- http://www.victim-prime.dsl.pipex.com/ -- http://mail.python.org/mailman/listinfo/python-list