Hello i have created 2 frames, and when I run this program it will show each frame as their own application (at least on windows). Is there a way to use both frames but put them in one application?
import wx
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.NewId(), "Main")
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.button = wx.Button(self, wx.NewId(), "Open a child")
self.sizer.Add(self.button, proportion=0, border=2, flag=wx.ALL)
self.SetSizer(self.sizer)
self.button.Bind(wx.EVT_BUTTON, self.on_button)
self.Layout()
def on_button(self, evt):
frame = ChildFrame(self)
frame.Show(True)
frame.MakeModal(True)
class ChildFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, wx.NewId(), "Child")
self.Bind(wx.EVT_CLOSE, self.on_close)
def on_close(self, evt):
self.MakeModal(False)
evt.Skip()
class MyApp(wx.App):
def OnInit(self):
frame = MainFrame()
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(0)
app.MainLoop()
Here is an image of what I do not want:
https://i.stack.imgur.com/7gayc.png
that is what I do not want,
I would like both frames to be in ONE application.
These frames already are running in the same wxPython application (
MyApp).Probably what you mean is to have the two frames/windows in the same wxPython window.
I think this is not possible because
wx.Frameclass is by definition an independent window.What you can do very easily is to modify your current classes to derive from
wx.Panelinstead of fromwx.Frameand then put the two panels in the same Common Frame.For example for the ChildFrame you modify like this:
Then you create the common Frame and instatiate your panels (and set them in a sizer):
If as suggested in Inerdial’s comment you are actually looking for MDI windows:
Then you have to use the wx.MDIParentFrame and wx.MDIChildFrame’s classes. For an example, check the MDIDemo.py example in the wxPython docs and demos package. Note that although wxPython supports Multiple Document Inteface windows, Windows has deprecated MDI.