wxpython: another missing attribute

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Salerno

    #1

    wxpython: another missing attribute

    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.Fr ame):

    def __init__(self, parent, id, title, pos=wx.DefaultP osition,
    size=wx.Default Size, style=wx.DEFAUL T_FRAME_STYLE,
    name='frame'):
    wx.Frame.__init __(self, parent, id, title, pos, size, style, name)
    panel = wx.Panel(self)
    text = wx.StaticText(p anel, -1, 'Click results')
    btnOK = wx.Button(panel , -1, 'OK')
    self.Bind(wx.EV T_BUTTON, self.clickOK, btnOK)
    btnCancel = wx.Button(panel , -1, 'Cancel')
    self.Bind(wx.EV T_BUTTON, self.clickCance l, btnCancel)
    sizer = wx.BoxSizer(wx. HORIZONTAL)
    sizer.Add(btnOK , 0, wx.ALL, 10)
    sizer.Add(btnCa ncel, 0, wx.ALL, 10)
    sizer.Add(text, 0, wx.ALL, 10)
    panel.SetSizer( sizer)

    def clickOK(self, event):
    self.text.SetLa bel('You clicked OK')

    def clickCancel(sel f, event):
    self.text.SetLa bel('You clicked Cancel')


    class MyApp(wx.App):

    def OnInit(self):
    frame = InputForm(None, -1, 'Data Entry Form')
    self.SetTopWind ow(frame)
    frame.Show()
    return True


    app = MyApp()
    app.MainLoop()

    -------------------

    Traceback (most recent call last):
    File "C:\Python24\my scripts\wx_test s\wxtest.py", line 23, in clickOK
    self.text.SetLa bel('You clicked OK')
    AttributeError: 'InputForm' object has no attribute 'text'
  • Morpheus

    #2
    Re: wxpython: another missing attribute


    "John Salerno" <johnjsal@NOSPA Mgmail.com> wrote in message
    news:mLiig.2280 $No6.48033@news .tufts.edu...[color=blue]
    > 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.Fr ame):
    >
    > def __init__(self, parent, id, title, pos=wx.DefaultP osition,
    > size=wx.Default Size, style=wx.DEFAUL T_FRAME_STYLE,
    > name='frame'):
    > wx.Frame.__init __(self, parent, id, title, pos, size, style,[/color]
    name)[color=blue]
    > panel = wx.Panel(self)
    > text = wx.StaticText(p anel, -1, 'Click results')[/color]

    This becomes a local var, i.e. local to __init__. To make it an instance var
    write

    self.text = wx.StaticText(p anel, -1, 'Click results')

    HTH
    Morpheus

    [color=blue]
    > btnOK = wx.Button(panel , -1, 'OK')
    > self.Bind(wx.EV T_BUTTON, self.clickOK, btnOK)
    > btnCancel = wx.Button(panel , -1, 'Cancel')
    > self.Bind(wx.EV T_BUTTON, self.clickCance l, btnCancel)
    > sizer = wx.BoxSizer(wx. HORIZONTAL)
    > sizer.Add(btnOK , 0, wx.ALL, 10)
    > sizer.Add(btnCa ncel, 0, wx.ALL, 10)
    > sizer.Add(text, 0, wx.ALL, 10)
    > panel.SetSizer( sizer)
    >
    > def clickOK(self, event):
    > self.text.SetLa bel('You clicked OK')
    >
    > def clickCancel(sel f, event):
    > self.text.SetLa bel('You clicked Cancel')
    >
    >
    > class MyApp(wx.App):
    >
    > def OnInit(self):
    > frame = InputForm(None, -1, 'Data Entry Form')
    > self.SetTopWind ow(frame)
    > frame.Show()
    > return True
    >
    >
    > app = MyApp()
    > app.MainLoop()
    >
    > -------------------
    >
    > Traceback (most recent call last):
    > File "C:\Python24\my scripts\wx_test s\wxtest.py", line 23, in clickOK
    > self.text.SetLa bel('You clicked OK')
    > AttributeError: 'InputForm' object has no attribute 'text'[/color]


    Comment

    • John Salerno

      #3
      Re: wxpython: another missing attribute

      Morpheus wrote:
      [color=blue]
      > This becomes a local var, i.e. local to __init__. To make it an instance var
      > write
      >
      > self.text = wx.StaticText(p anel, -1, 'Click results')[/color]

      Ah, more namespace trickery! Thanks! :)

      Comment

      Working...