<div dir="ltr"><div>Hi folks!</div>
<div>&nbsp;</div>
<div>I hope I&#39;m in the right place to ask this question.&nbsp; I&#39;m new to Python and have been working through some tutorials and have made it to the GUI creation stage.&nbsp; All I was hoping to do with the code below, was to open a &quot;secondary&quot; window and have some text end up on a text_ctrl, but I get an error message that looks like this:</div>

<div>&nbsp;</div>
<div>Traceback (most recent call last):<br>&nbsp; File &quot;textbox2TEST.py&quot;, line 36, in MainToSecond<br>&nbsp;&nbsp;&nbsp; MySecondFrame.text_ctrl_2.SetValue(&quot;This text was generated from the &#39;MainFrame&#39; window&quot;)<br>
AttributeError: type object &#39;MySecondFrame&#39; has no attribute &#39;text_ctrl_2&#39;</div>
<div>&nbsp;</div>
<div>I&#39;m using wxGlade and SPE together, so almost all of the code is generated for me.&nbsp; I just don&#39;t get why it doesn&#39;t work, although I think it has to do with one class referencing another class, and I&#39;m obviously not doing that correctly...&nbsp; Any help is much appreciated!&nbsp;</div>

<div>&nbsp;</div>
<div>Here&#39;s the code that created the error:</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>import wx</div>
<div>&nbsp;</div>
<div>class MyMainFrame(wx.Frame):<br>&nbsp;&nbsp;&nbsp; def __init__(self, *args, **kwds):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # begin wxGlade: MyMainFrame.__init__<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kwds[&quot;style&quot;] = wx.DEFAULT_FRAME_STYLE<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wx.Frame.__init__(self, *args, **kwds)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.text_ctrl_1 = wx.TextCtrl(self, -1, &quot;&quot;, style=wx.TE_MULTILINE)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.button_1 = wx.Button(self, -1, &quot;Click me to bring up second window and write some text&quot;)</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.__set_properties()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.__do_layout()</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.Bind(wx.EVT_BUTTON, self.MainToSecond, self.button_1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # end wxGlade</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; def __set_properties(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # begin wxGlade: MyMainFrame.__set_properties<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.SetTitle(&quot;Main Frame&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # end wxGlade</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; def __do_layout(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # begin wxGlade: MyMainFrame.__do_layout<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizer_1 = wx.BoxSizer(wx.VERTICAL)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizer_2 = wx.BoxSizer(wx.VERTICAL)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizer_2.Add(self.text_ctrl_1, 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizer_2.Add(self.button_1, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.SetSizer(sizer_1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizer_1.Fit(self)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.Layout()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # end wxGlade</div>

<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; def MainToSecond(self, event): # wxGlade: MyMainFrame.&lt;event_handler&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MySecondFrame(self).Show()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MySecondFrame.text_ctrl_2.SetValue(&quot;This text was generated from the &#39;MainFrame&#39; window&quot;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </div>
<div>&nbsp;</div>
<div># end of class MyMainFrame<br>class MySecondFrame(wx.Frame):<br>&nbsp;&nbsp;&nbsp; def __init__(self, *args, **kwds):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # begin wxGlade: MySecondFrame.__init__<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kwds[&quot;style&quot;] = wx.DEFAULT_FRAME_STYLE<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wx.Frame.__init__(self, *args, **kwds)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.text_ctrl_2 = wx.TextCtrl(self, -1, &quot;&quot;, style=wx.TE_MULTILINE)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.button_2 = wx.Button(self, -1, &quot;Click me to close this frame and send some text back to the MainFrame&quot;)</div>

<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.__set_properties()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.__do_layout()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # end wxGlade</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; def __set_properties(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # begin wxGlade: MySecondFrame.__set_properties<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.SetTitle(&quot;Frame Number Two&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # end wxGlade</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; def __do_layout(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # begin wxGlade: MySecondFrame.__do_layout<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizer_3 = wx.BoxSizer(wx.HORIZONTAL)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizer_4 = wx.BoxSizer(wx.VERTICAL)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizer_4.Add(self.text_ctrl_2, 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizer_4.Add(self.button_2, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizer_3.Add(sizer_4, 1, wx.EXPAND, 0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.SetSizer(sizer_3)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizer_3.Fit(self)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.Layout()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # end wxGlade</div>

<div>&nbsp;</div>
<div># end of class MySecondFrame</div>
<div>&nbsp;</div>
<div>if __name__ == &quot;__main__&quot;:<br>&nbsp;&nbsp;&nbsp; app = wx.PySimpleApp(0)<br>&nbsp;&nbsp;&nbsp; wx.InitAllImageHandlers()<br>&nbsp;&nbsp;&nbsp; frame_1 = MyMainFrame(None, -1, &quot;&quot;)<br>&nbsp;&nbsp;&nbsp; app.SetTopWindow(frame_1)<br>&nbsp;&nbsp;&nbsp; frame_1.Show()<br>&nbsp;&nbsp;&nbsp; app.MainLoop()</div>

<div>&nbsp;</div></div>