Python/wxPython: How to get text display in a second frame from the main frame
Question: Am new to Python/wxPython, I created a text two frames using `wxFormBuilder`.
The purpose is to add two numbers and display the result on both frames
`OnAdd` button click.

I have done all I could but no success?

My problem is how do I get the Final_Result display on the second frame that
gets call when the add button is press as par the code below;

**Note:** the codes are in 3 separate files (q1.py, q2.py, and q3.py). q2.py
is the main running file while q1.py, and q2.py create the frames respectively
as generated from wxFormBuilder.

**q1.py**

    
    
    import wx
    import wx.xrc
    
    class MyFrame1 ( wx.Frame ):
    
        def __init__( self, parent ):
            wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString,   pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.TAB_TRAVERSAL )
    
            self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
    
            Sizer1 = wx.BoxSizer( wx.VERTICAL )
    
            Sizer2 = wx.GridSizer( 0, 2, 0, 0 )
    
            self.val1 = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
            self.val1.SetFont( wx.Font( 30, 70, 90, 90, False, wx.EmptyString ) )
    
            Sizer2.Add( self.val1, 1, wx.ALL|wx.EXPAND, 5 )
    
            self.val2 = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
            self.val2.SetFont( wx.Font( 30, 70, 90, 90, False, wx.EmptyString ) )
    
            Sizer2.Add( self.val2, 1, wx.ALL|wx.EXPAND, 5 )
    
            self.Calc = wx.Button( self, wx.ID_ANY, u"Add", wx.DefaultPosition, wx.DefaultSize, 0 )
            self.Calc.SetFont( wx.Font( 30, 70, 90, 90, False, wx.EmptyString ) )
    
            Sizer2.Add( self.Calc, 1, wx.ALL|wx.EXPAND, 5 )
    
            self.result = wx.StaticText( self, wx.ID_ANY, u"Result", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE )
            self.result.Wrap( -1 )
            self.result.SetFont( wx.Font( 30, 70, 90, 90, False, wx.EmptyString ) )
    
            Sizer2.Add( self.result, 1, wx.ALL|wx.EXPAND, 5 )
    
    
            Sizer1.Add( Sizer2, 1, wx.EXPAND, 5 )
    
    
            self.SetSizer( Sizer1 )
            self.Layout()
    
            self.Centre( wx.BOTH )
    
            # Connect Events
            self.Calc.Bind( wx.EVT_BUTTON, self.addFunc )
    
        def __del__( self ):
            pass
    
    #===================================================
    

**q2.py**

    
    
    #!/usr/bin/python
    # -*- coding: utf-8 -*- 
    
    import wx
    from q1 import MyFrame1
    from q3 import MyFrame3
    
    
    class MyFrame2(MyFrame1):
        def __init__(self, parent):
            MyFrame1.__init__ (self, parent)
    
        def addFunc( self, event ):
            val1 = float(self.val1.GetValue())
            val2 = float(self.val2.GetValue())
    
            add = val1 + val2
    
            self.result.SetLabel(str(add))
    
            self.result = MyFrame4(self)
            self.result.Show()
    
            self.Final_Result.SetLabel(str(add))
    
    
    
    class MyFrame4(MyFrame3):
        """docstring for my_temp_Frame"""
        def __init__(self, parent):
            MyFrame3.__init__ (self, parent)
    
    
    
    
    if __name__ == "__main__":
    
        app = wx.App(0)
        MyFrame2(None).Show()
        app.MainLoop()
    
    
    #===================================================
    

**q3.py**

    
    
    import wx
    import wx.xrc
    
    class MyFrame3 ( wx.Frame ):
    
        def __init__( self, parent ):
            wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,100 ), style = wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.TAB_TRAVERSAL )
    
            self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
    
            Sizer1 = wx.BoxSizer( wx.VERTICAL )
    
            Sizer2 = wx.GridSizer( 0, 2, 0, 0 )
    
            self.Text = wx.TextCtrl( self, wx.ID_ANY, u"You result is:", wx.DefaultPosition, wx.DefaultSize, wx.TE_READONLY )
            self.Text.SetFont( wx.Font( 20, 70, 90, 90, False, wx.EmptyString ) )
    
            Sizer2.Add( self.Text, 1, wx.ALL|wx.EXPAND, 5 )
    
            self.Final_Result = wx.StaticText( self, wx.ID_ANY, u"Final_Result", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE )
            self.Final_Result.Wrap( -1 )
            self.Final_Result.SetFont( wx.Font( 30, 70, 90, 90, False, wx.EmptyString ) )
            self.Final_Result.SetForegroundColour( wx.Colour( 255, 255, 255 ) )
            self.Final_Result.SetBackgroundColour( wx.Colour( 255, 0, 0 ) )
    
            Sizer2.Add( self.Final_Result, 1, wx.ALL|wx.EXPAND, 5 )
    
    
            Sizer1.Add( Sizer2, 1, wx.EXPAND, 5 )
    
    
            self.SetSizer( Sizer1 )
            self.Layout()
    
            self.Centre( wx.BOTH )
    
        def __del__( self ):
            pass
    
    
    #===================================================
    

Thanks in advance.


Answer: I have rarely seen a more convoluted way to simply have two frames in wxPython
and transferring data from one into the other. But maybe you have your good
reasons. If not, have a look at
[this](http://wiki.wxpython.org/ModelViewController). It opened the eyes at
least for me how to cleanly separate logic and GUI.

**Answer** : You should have got on calling:

    
    
        self.result = MyFrame4(self)
        # ...
        self.Final_Result.SetLabel(str(add))
    

the error message:

    
    
    AttributeError: 'MyFrame2' object has no attribute 'Final_Result'
    

which simply means that there is no `Final_Result` in `MyFrame2`. After some
looking `Final_result` can be found in `MyFrame3` which is the base class for
`MyFrame4`. We also learn that `MyFrame4` is set as object attribute
`self.result` in `MyFrame2`

So simply change the offending line to:

    
    
        self.result.Final_Result.SetLabel(str(add))
    

and you are done.

