[Tutor] Is this a "Class" problem?

Jeff Younker jeff at drinktomi.com
Mon Aug 18 21:29:52 CEST 2008


On Aug 18, 2008, at 9:13 AM, Adrian Greyling wrote:

>     def MainToSecond(self, event): # wxGlade:  
> MyMainFrame.<event_handler>
>         MySecondFrame(self).Show()
>         MySecondFrame.text_ctrl_2.SetValue("This text was generated  
> from the 'MainFrame' window")

The expression MySecondFrame(self) creates a new object.  It
initializes the new object by calling the MySecondFrame's __init__
method.

> class MySecondFrame(wx.Frame):
>     def __init__(self, *args, **kwds):
>         # begin wxGlade: MySecondFrame.__init__
> ...
>        self.text_ctrl_2 = wx.TextCtrl(self, -1, "",  
> style=wx.TE_MULTILINE)
> ...



The __init__ method calls sets the variable text_ctrl_2 in the object
m.

Your function MainToSecond is trying to get the attribute  
MySecondFrame.text_ctrl_2.
This attribute does not exist.  You want to get the attribute  
m.text_ctrl_2.  So, the method
should be:

     def MainToSecond(self, event): # wxGlade:  
MyMainFrame.<event_handler>
         m = MySecondFrame(self)
         m.Show()
         m.text_ctrl_2.SetValue("This text was generated from the  
'MainFrame' window")


Also, method and function names should always start with a lower case  
letter: always
mainToSecond and never MainToSecond

-jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080818/419ad5a0/attachment-0001.htm>


More information about the Tutor mailing list