Dear all,
I built 2 script to manage 2 different frames (which I will then convert to exe with py2exe).
Frame 1 (GG1) is like this

import wx

# begin wxGlade: extracode
# end wxGlade


class MyFrame(wx.Frame):
functions here
...

if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    GG1 = MyFrame(None, -1, "")
    app.SetTopWindow(GG1)
    GG1.Show()
    app.MainLoop()

Everything is fine. Now I would like to open another independent frame (GG2)

import wx

# begin wxGlade: extracode
# end wxGlade


class MyFrame(wx.Frame):
functions here
...

if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    GG2= MyFrame(None, -1, "")
    app.SetTopWindow(GG2)
    GG2.Show()
    app.MainLoop()

GG1 and GG2 are in 2 py files. Is there a ways for them to share values (something I enter in a GG2 box to be copied in one GG1 box)? Or to do something like
GG1 opens GG2
GG1 closes
when I close GG2
GG1 opens

Otherwise, since GG1 has a function that search for a text file when it opens, I can I ask GG1 to search again for that file after GG2 closes?

I know it's a bit confusing... sorry about that and thanks for your help,
Gianluca

You could import your frame2 file into your frame1 code and instantiate it there.

Another way is to use a third class as a wrapper. The buttons in the following code print the contents of the variable from the other class. Also, it is never a good idea to create two or more instances of a GUI at the same time. It can cause confusion with the interaction from the display manager. Use one of instance of wx and separate frames.

import wx

class Test1():
    def __init__(self, parent, id, title):
        self.ident="Test1 Ident"
        self.frame=wx.Frame(None, id, title, size=(170, 100))
        self.frame.SetPosition((10, 10))

    def exit_button(self, T2):
        panel = wx.Panel(self.frame, -1)
        exit = wx.Button(panel, -1, 'Exit 1'+T2.ident, (10, 10))

        exit.Bind(wx.EVT_BUTTON,  self.exit_this, id=exit.GetId())
        self.frame.Show(True)

    def exit_this(self, event):
        self.frame.Close()

class Test2():
    def __init__(self, parent, id, title, wrap):
        self.ident="Test2"
        self.frame=wx.Frame(None, id, title, size=(170, 100))
        self.frame.SetPosition((10, 150))

        panel = wx.Panel(self.frame, -1)
        exit = wx.Button(panel, -1, 'Exit Two-->'+wrap.T1.ident, (10, 10))
        exit.Bind(wx.EVT_BUTTON,  self.exit_this, id=exit.GetId())

        self.frame.Show(True)

    def exit_this(self, event):
        self.frame.Close()

class Wrapper():
    def __init__(self):
        app = wx.App()
        self.T1=Test1(None, -1, '')
        self.T2=Test2(None, -1, '', self)
        self.T1.exit_button(self.T2)
        app.MainLoop()

W = Wrapper()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.