Pass values between 2 frames

Hi

How can I pass values between two frames. I have text control in first frame . If I type something on the text control and then when I press ok. My second frame opens and in that frame I have to get the value I typed on first frame and then It should put in the text control on the second frame. How can I do that.

Here is my sample code.

import wx
import os, sys
import string
import re
import wx.lib.dialogs

···

#########################

class MyFrame1(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self, parent,-1,title,wx.DefaultPosition,wx.Size(450,450))

        self.mainpa = wx.Panel(self,-1,wx.DefaultPosition, wx.DefaultSize)
       
        self.rb1 = wx.RadioButton(self.mainpa,10,"Analyze",wx.Point(20,40),style = wx.RB_GROUP)
        self.Bind(wx.EVT_RADIOBUTTON, self.OnOk,id =10)
       
        self.text1 = wx.TextCtrl(self.mainpa,-1,"",(140,40),(155,-1))
       

        b2 =wx.Button(self.mainpa,30,'Ok',(300,340))
        self.Bind(wx.EVT_BUTTON,self.OnOk,b2)

        cancel_bt2 =wx.Button(self.mainpa,-1,'Cancel',(200,340))
        self.Bind(wx.EVT_BUTTON,self.OnCancel,cancel_bt2)

   
    def OnOk(self,event):
           if (self.rb1.GetValue()== True):
                   self.dlg = MyFrame2(self,-1)
                   self.dlg.Show(True)
           
    def OnCancel(self,event):
            self.Close()

class MyFrame2(wx.Frame):
def init(self, parent, id, title=“Second Frame”):
wx.Frame.init(self, parent,-1,title,wx.DefaultPosition,wx.Size(450,450))

        self.mainpa = wx.Panel(self,-1,wx.DefaultPosition, wx.DefaultSize)
      
        self.stext1 = wx.StaticText(self.mainpa,-1,"File Name",(20,10))
           
        self.text2 = wx.TextCtrl(self.mainpa,-1,"",(120,10),(155,-1))

class MyApp(wx.App):
def OnInit(self):
frame = MyFrame1(None, -1, ‘First Frame’)
frame.Show(True)
self.SetTopWindow(frame)
return True

app = MyApp(0)
app.MainLoop()

Thanks costanzi

···

-----Original Message-----
From: costanzi [mailto:g.costanzi@idi.it]
Sent: Wednesday, November 14, 2007 4:46 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Pass values between 2 frames

Thippana, Prasoonadevi wrote:

Hi

How can I pass values between two frames. I have text control in first

frame . If I type something on the text control and then when I press
ok. My second frame opens and in that frame I have to get the value I
typed on first frame and then It should put in the text control on the

second frame. How can I do that.
Here is my sample code.

import wx
import os, sys
import string
import re
import wx.lib.dialogs

#########################

class MyFrame1(wx.Frame):
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self,
parent,-1,title,wx.DefaultPosition,wx.Size(450,450))
           
            self.mainpa = wx.Panel(self,-1,wx.DefaultPosition,
wx.DefaultSize)
           
            self.rb1 =
wx.RadioButton(self.mainpa,10,"Analyze",wx.Point(20,40),style =
wx.RB_GROUP)
            self.Bind(wx.EVT_RADIOBUTTON, self.OnOk,id =10)
           
            self.text1 =
wx.TextCtrl(self.mainpa,-1,"",(140,40),(155,-1))
           
            b2 =wx.Button(self.mainpa,30,'Ok',(300,340))
            self.Bind(wx.EVT_BUTTON,self.OnOk,b2)

            cancel_bt2 =wx.Button(self.mainpa,-1,'Cancel',(200,340))
            self.Bind(wx.EVT_BUTTON,self.OnCancel,cancel_bt2)

        def OnOk(self,event):
               if (self.rb1.GetValue()== True):
                       self.dlg = MyFrame2(self,-1)
                       self.dlg.Show(True)
               
        def OnCancel(self,event):
                self.Close()

class MyFrame2(wx.Frame):
        def __init__(self, parent, id, title="Second Frame"):
            wx.Frame.__init__(self,
parent,-1,title,wx.DefaultPosition,wx.Size(450,450))
           
            self.mainpa = wx.Panel(self,-1,wx.DefaultPosition,
wx.DefaultSize)
          
            self.stext1 = wx.StaticText(self.mainpa,-1,"File
Name",(20,10))
               
            self.text2 =
wx.TextCtrl(self.mainpa,-1,"",(120,10),(155,-1))
                                        
class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame1(None, -1, 'First Frame')
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

app = MyApp(0)
app.MainLoop()

  def OnOk(self,event):

            sMyVariable = str(self.text1.GetValue())
            if (self.rb1.GetValue()== True):
                self.dlg = MyFrame2(self,-1)
                self.dlg.text2.SetValue(sMyVariable)
                self.dlg.Show(True)

Ciao
Beppe
Python-it.org

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org