Idora
unread,Dec 22, 2008, 3:21:29 PM12/22/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ShowMeDo-Learners
I get the following error message when I run script from the wxPython
series. The script should be identical to what was displayed in the
screencast, yet it doesn't run.
Any ideas would be appreciated.
Thanks,
Idora
Here's the error message from the Shell:
--------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\tkelly\Python Scripts\simpleGuiMain_Original3.pyw",
line 41, in <module>
frame = MainWindow(None,-1,"Small Editor") # calls parent class
(MainWindow) & creates instance
File "C:\Users\tkelly\Python Scripts\simpleGuiMain_Original3.pyw",
line 26, in __init__
wx.EVT_MENU(self, ID_ABOUT, self.OnAbout )
AttributeError: 'MainWindow' object has no attribute 'OnAbout'
I get that Python thinks the OnAbout attribute isn't part of
MainWindow, yet the code is identical to Kyran's in the screencast and
his works, while mine borks.
Here's the actual script (my version):
---------------------------------------------------------
import wx
ID_ABOUT = 101
ID_EXIT = 110
''' creates a simple, empty window '''
class MainWindow(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,wx.ID_ANY,title, size = (400,200),
style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
self.control = wx.TextCtrl(self,1,style = wx.TE_MULTILINE)
# add status bar
self.CreateStatusBar()
# set up the menu
filemenu = wx.Menu()
filemenu.Append(ID_ABOUT, "&About", "Info about this program")
filemenu.AppendSeparator()
filemenu.Append(ID_EXIT, "E&xit", "Terminate the program")
# create the menu
menubar = wx.MenuBar()
menubar.Append(filemenu,"&File")
self.SetMenuBar(menubar)
# setting/bind event handlers
wx.EVT_MENU( self, ID_ABOUT, self.OnAbout )
wx.EVT_MENU( self, ID_EXIT, self.OnExit )
self.Show(True)
# creating the event handlers
def OnAbout( self, event ):
d = wx.MessageDialog( self, "A simple editor \n in
wxPython" ,"About Simple Editor", wx.OK) # create a message dialog
box
d.ShowModal() # shows it
d.Destroy() # finally destroys it
def OnExit( self, event ):
self.Close(True) # closes the window
app = wx.PySimpleApp() # simple wrapper bundled with Python; a sub-
class
frame = MainWindow(None,-1,"Small Editor") # calls parent class
(MainWindow) & creates instance
app.MainLoop() # starts app main loop