wxpython: another missing attribute
Morpheus
Fri Jun 9 14:20:29 EDT 2006
"John Salerno" <johnjsal at NOSPAMgmail.com> wrote in message
news:mLiig.2280$No6.48033 at news.tufts.edu...
> Ah, the object-oriented stuff is just so FUN! :) Here's my code,
> followed by the error. I thought I was referring to the 'text' attribute
> correctly, but it seems not.
>
> import wx
>
>
> class InputForm(wx.Frame):
>
> def __init__(self, parent, id, title, pos=wx.DefaultPosition,
> size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE,
> name='frame'):
> wx.Frame.__init__(self, parent, id, title, pos, size, style,
name)
> panel = wx.Panel(self)
> text = wx.StaticText(panel, -1, 'Click results')
This becomes a local var, i.e. local to __init__. To make it an instance var
write
self.text = wx.StaticText(panel, -1, 'Click results')
HTH
Morpheus
> btnOK = wx.Button(panel, -1, 'OK')
> self.Bind(wx.EVT_BUTTON, self.clickOK, btnOK)
> btnCancel = wx.Button(panel, -1, 'Cancel')
> self.Bind(wx.EVT_BUTTON, self.clickCancel, btnCancel)
> sizer = wx.BoxSizer(wx.HORIZONTAL)
> sizer.Add(btnOK, 0, wx.ALL, 10)
> sizer.Add(btnCancel, 0, wx.ALL, 10)
> sizer.Add(text, 0, wx.ALL, 10)
> panel.SetSizer(sizer)
>
> def clickOK(self, event):
> self.text.SetLabel('You clicked OK')
>
> def clickCancel(self, event):
> self.text.SetLabel('You clicked Cancel')
>
>
> class MyApp(wx.App):
>
> def OnInit(self):
> frame = InputForm(None, -1, 'Data Entry Form')
> self.SetTopWindow(frame)
> frame.Show()
> return True
>
>
> app = MyApp()
> app.MainLoop()
>
> -------------------
>
> Traceback (most recent call last):
> File "C:\Python24\myscripts\wx_tests\wxtest.py", line 23, in clickOK
> self.text.SetLabel('You clicked OK')
> AttributeError: 'InputForm' object has no attribute 'text'
More information about the Python-list
mailing list