Help - problem with code in wxPython screencasts

86 views
Skip to first unread message

Idora

unread,
Dec 22, 2008, 3:21:29 PM12/22/08
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

Kyran Dale

unread,
Dec 22, 2008, 4:48:51 PM12/22/08
to showmedo...@googlegroups.com
Hi Idora,
looking at your script, you appear to have defined OnAbout(... within
the __init__ method. This line:

> # creating the event handlers
> def OnAbout( self, event ): [...]

should be at the same indent level as this line

> def __init__(self,parent,id,title):

both __init__ and OnAbout are methods of the MainWindow class and
should start at the same text-column. Python has significant
whitespace so one should always be aware of the indent-degree of any
code-block.

cheers,
kyran

Idora

unread,
Dec 22, 2008, 5:02:11 PM12/22/08
to ShowMeDo-Learners
Am enjoying working through the various Python series. Are you
planning on any more wxPython screencasts


On Dec 22, 9:48 pm, "Kyran Dale" <kyran.d...@gmail.com> wrote:
> Hi Idora,
> looking at your script, you appear to have defined OnAbout(... within
> the __init__ method. This line:
>
> >                # creating the event handlers
> >                def OnAbout( self,  event ): [...]
>
> should be at the same indent level as this line
>
> >        def __init__(self,parent,id,title):
>
> both __init__ and OnAbout are methods of the MainWindow class and
> should start at the same text-column. Python has significant
> whitespace so one should always be aware of the indent-degree of any
> code-block.
>
> cheers,
> kyran
>

Kyran Dale

unread,
Dec 22, 2008, 5:31:16 PM12/22/08
to showmedo...@googlegroups.com
On Mon, Dec 22, 2008 at 10:02 PM, Idora <tonyk...@gmail.com> wrote:
>
> Am enjoying working through the various Python series. Are you
> planning on any more wxPython screencasts
>

just working on some big changes to showmedo to improve learning
significantly. Once those are implemented I have a number of wxpython
and PyQt learning-paths planned for the club. But I'll be launching a
little content drive and trying to drum up some more wxpython content.
Watch this space.

glad you're enjoying the vids,
kyran

Idora

unread,
Dec 22, 2008, 8:00:42 PM12/22/08
to ShowMeDo-Learners
cheers, Kyran.

Thanks a lot for your help

On Dec 22, 10:31 pm, "Kyran Dale" <kyran.d...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages