[Tutor] wxPython problem

Øyvind python at kapitalisten.no
Mon Sep 26 13:41:32 CEST 2005


I have been reading the
http://wiki.wxpython.org/index.cgi/Getting_20Started manual and are
running the program there. (Enclosed below).

When I run it, it works fine. But, when I run it again, I get the error
PyNoAppError: The wx.App object must be created first! I assume I have
killed the object and have to create it again. But how would I do that?
reload(MainWindow) does not work. Any suggestions?

Thanks in advance.

import os
import wx
class MainWindow(wx.Frame):
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,wx.ID_ANY, title, size = ( 200,100),

        self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
        self.CreateStatusBar() # A StatusBar in the bottom of the window
        # Setting up the menu.
        filemenu= wx.Menu()
        filemenu.Append(ID_ABOUT, "&About"," Information about this program")
        filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
        # Creating the menubar.
        menuBar = wx.MenuBar()
        menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the
        self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
        wx.EVT_MENU(self, ID_ABOUT, self.OnAbout) # attach the menu-event
ID_ABOUT to the
                                                           # method
        wx.EVT_MENU(self, ID_EXIT, self.OnExit)   # attach the menu-event
ID_EXIT to the
                                                           # method
    def OnAbout(self,e):
        d= wx.MessageDialog( self, " A sample editor \n"
                            " in wxPython","About Sample Editor", wx.OK)
                            # Create a message dialog box
        d.ShowModal() # Shows it
        d.Destroy() # finally destroy it when finished.
    def OnExit(self,e):
        self.Close(True)  # Close the frame.
app = wx.PySimpleApp()
frame = MainWindow(None, -1, "Sample editor")

This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

More information about the Tutor mailing list