how to pass globals across modules (wxPython)
Fredrik Lundh
fredrik at pythonware.com
Mon Dec 20 02:37:07 EST 2004
Martin Drautzburg wrote:
> My wxPython program starts execution in mainFrame.py like this
> [...]
> class MainApp(wxApp):
> def OnInit(self):
> self.mainFrame = MainFrame(None)
> self.mainFrame.Show()
> self.SetTopWindow(self.mainFrame)
> return True
>
>
> def main():
> global application
> application=MainApp(0)
> application.MainLoop()
>
>
> if __name__ == '__main__':
> main()
>
>
> I need to access the "application" object from other modules, actually
> the windows and frames that live therein and I don't know how to do
> this.
this might help:
http://www.python.org/doc/faq/programming.html#how-do-i-share-global-variables-across-modules
> I tried using "global", but that does not seem to help. In the other
> module I run an "import mainFrame" and that seems to reset the global
> variables.
"global" is used in a local scope to tell Python that something isn't a
local variable; see
http://www.python.org/doc/faq/programming.html#how-do-you-set-a-global-variable-in-a-function
http://www.python.org/doc/faq/programming.html#what-are-the-rules-for-local-and-global-variables-in-python
and
http://docs.python.org/ref/naming.html
for details.
</F>
More information about the Python-list
mailing list