Hi, all.
I’m a newbie in Python and wxPython and I got problem using more than two source file.
Most examples uses one source file, but it is not realistic so that I tried to use two source files, then I got stuck.
I first created the main application source file as follows:
from wxPython.wx import *
class MainApp(wxApp):
def OnInit(self):
from MainFrame import *
mainFrame = MainFrame(NULL)
mainFrame.Show( true )
self.SetTopWindow( mainFrame )
return true
app = ConceptualPhysicsApp( 0 )
app.MainLoop()
I created MainFrame.py at the same directory and I imported MainFrame as in the above code. I first tried “import MainFrame”, but it didn’t work at all.
Here is some part of MainFrame.py
from wxPython.wx import *
class MainFrame( wxMDIParentFrame ):
def __init__( self, parent ):
menu = self.makeMenu()
self.SetMenuBar( menu )
EVT_MENU( self, ID_OPEN, self.OnMenuOpen )
EVT_MENU( self, ID_CLOSE, self.OnMenuClose )
EVT_MENU( self, ID_SAVE, self.OnMenuSave )
EVT_MENU( self, ID_SAVEAS, self.OnMenuSaveAs )
EVT_MENU( self, ID_EXIT, self.OnMenuExit )
EVT_MENU( self, ID_ABOUT, self.OnMenuAbout )
EVT_CLOSE( self, self.OnCloseWindow )
def makeMenu( self ):
fmenu = wxMenu()
fmenu.Append( ID_OPEN, "&Open...", "Open saved file" )
fmenu.Append( ID_CLOSE, "&Close...", "Close file" )
fmenu.Append( ID_SAVE, "&Save...", "Save file" )
fmenu.Append( ID_SAVEAS, "Save &As", "Save as file" )
fmenu.AppendSeparator()
fmenu.Append( ID_EXIT, "E&xit", "Quit the program" )
…
I tried to run MainApp by typing “python MainApp.py” in the directory I saved them and I got the following error message.
Traceback (most recent call last):
…
File “MainFrame.py”, line 22, in makeMenu
fmenu.Append( ID_OPEN, "&Open...", "Open saved file" )
NameError: global name ‘ID_OPEN’ is not defined.
I guess I should import something for ID_OPEN, but I don’t know what.
Could you help me solve this problem?
Thanks in advance.
YJ