471,350 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

wxPython Multiple Frames using Boa Constructor

I have 2 frames and on a button click event on frame 1 I want to hide frame 1 and show frame 2
I can hide frame 1 but frame 2 does not appear.

I would really appreciate all the help.
I am learning progamming so please go easy on the terminologies

Heres the code
***********app1.py*******autogenerated code
Expand|Select|Wrap|Line Numbers
  1. import wx
  2.  
  3. import Frame2
  4. import Frame1
  5.  
  6. modules ={'Frame1': [0, '', u'Frame1.py'], 'Frame2': [2, 'Second frame', u'Frame2.py']}
  7.  
  8.  
  9. class BoaApp(wx.App):
  10.     def OnInit(self):
  11.         self.main = Frame1.create(None)
  12.         self.main.Show()
  13.         self.SetTopWindow(self.main)
  14.         return True
  15.  
  16. def main():
  17.     application = BoaApp(0)
  18.     application.MainLoop()
  19.  
  20. if __name__ == '__main__':
  21.     main()
***************Frame1.py*************************
Expand|Select|Wrap|Line Numbers
  1.  
  2. #Boa:Frame:Frame1
  3.  
  4. import wx
  5. import Frame2
  6.  
  7. def create(parent):
  8.     return Frame1(parent)
  9.  
  10. [wxID_FRAME1, wxID_FRAME1BUTTON1] = [wx.NewId() for _init_ctrls in range(4)]
  11.  
  12. class Frame1(wx.Frame):
  13.     def _init_ctrls(self, prnt):
  14.  
  15.         wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
  16.               pos=wx.Point(423, 374), size=wx.Size(374, 226),
  17.               style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
  18.         self.SetClientSize(wx.Size(366, 199))
  19.  
  20.         self.button1 = wx.Button(id=wxID_FRAME1BUTTON1,
  21.               label='Hide frame1 and show frame 2', name='button1', parent=self,
  22.               pos=wx.Point(56, 56), size=wx.Size(270, 47), style=0)
  23.         self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
  24.               id=wxID_FRAME1BUTTON1)
  25.  
  26.             def __init__(self, parent):
  27.                   self._init_ctrls(parent)
  28.  
  29.     def OnButton1Button(self, event):
  30.  
  31.         #frm1=self.Frame1()
  32.         self.Hide()                #Frame1 does get hidden but 
  33.         frm2 = Frame2()
  34.         frm2.Show()            #Frame 2 does not appear
******************************Frame 2************************
Expand|Select|Wrap|Line Numbers
  1.  
  2. class Frame2(wx.Frame):
  3.     def _init_ctrls(self, prnt):
  4.         # generated method, don't edit
  5.         wx.Frame.__init__(self, id=wxID_FRAME2, name='', parent=prnt,
  6.               pos=wx.Point(451, 306), size=wx.Size(504, 360),
  7.               style=wx.DEFAULT_FRAME_STYLE, title='Frame2')
  8.         self.SetClientSize(wx.Size(496, 333))
  9.  
  10.         self.grid1 = wx.grid.Grid(id=wxID_FRAME2GRID1, name='grid1',
  11.               parent=self, pos=wx.Point(16, 48), size=wx.Size(472, 272),
  12.               style=0)
  13.  
  14.     def __init__(self, parent):
  15.         self._init_ctrls(parent)
  16.         self.grid1.CreateGrid(5,5)
  17.         self.grid1.Show()
  18.  
  19.         for i in range (0, 4):
  20.             for j in range (0, 4):
  21.                 self.grid1.SetCellValue(i, j, ("%s,%s") % (i, j))
Sep 21 '07 #1
3 6073
bartonc
6,596 Expert 4TB
This should work. Your way may also have worked if you had given the "parent" argument to frame2(). I'm thinking that you are getting an error printed in the Boa Constructor report area, but it is collapsed.

Expand|Select|Wrap|Line Numbers
  1. #Boa:Frame:Frame1
  2.  
  3. import wx
  4. import Frame2
  5.  
  6. def create(parent):
  7.     return Frame1(parent)
  8.  
  9. [wxID_FRAME1, wxID_FRAME1BUTTON1] = [wx.NewId() for _init_ctrls in range(4)]
  10.  
  11. class Frame1(wx.Frame):
  12.     def _init_ctrls(self, prnt):
  13.  
  14.         wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
  15.               pos=wx.Point(423, 374), size=wx.Size(374, 226),
  16.               style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
  17.         self.SetClientSize(wx.Size(366, 199))
  18.  
  19.         self.button1 = wx.Button(id=wxID_FRAME1BUTTON1,
  20.               label='Hide frame1 and show frame 2', name='button1', parent=self,
  21.               pos=wx.Point(56, 56), size=wx.Size(270, 47), style=0)
  22.         self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
  23.               id=wxID_FRAME1BUTTON1)
  24.  
  25.             def __init__(self, parent):
  26.                   self._init_ctrls(parent)
  27.                   # it's OK to edit this. In fact, this is the place TO edit in BC
  28.                   # !!! correction. need module.class for creation !!!
  29.                   self.frm2 = Frame2.Frame2(self)   # frame1 is the parent of frame2
  30.  
  31.     def OnButton1Button(self, event):
  32.  
  33.         #frm1=self.Frame1()
  34.         self.Hide()                #Frame1 does get hidden but 
  35.         self.frm2.Show()            #Frame 2 should appear
******************************Frame 2************************
Expand|Select|Wrap|Line Numbers
  1.  
  2. class Frame2(wx.Frame):
  3.     def _init_ctrls(self, prnt):
  4.         # generated method, don't edit
  5.         wx.Frame.__init__(self, id=wxID_FRAME2, name='', parent=prnt,
  6.               pos=wx.Point(451, 306), size=wx.Size(504, 360),
  7.               style=wx.DEFAULT_FRAME_STYLE, title='Frame2')
  8.         self.SetClientSize(wx.Size(496, 333))
  9.  
  10.         self.grid1 = wx.grid.Grid(id=wxID_FRAME2GRID1, name='grid1',
  11.               parent=self, pos=wx.Point(16, 48), size=wx.Size(472, 272),
  12.               style=0)
  13.  
  14.     def __init__(self, parent):
  15.         self._init_ctrls(parent)
  16.         self.grid1.CreateGrid(5,5)
  17.         self.grid1.Show()
  18.  
  19.         for i in range (0, 4):
  20.             for j in range (0, 4):
  21.                 self.grid1.SetCellValue(i, j, ("%s,%s") % (i, j))
Sep 22 '07 #2
bartonc
6,596 Expert 4TB
Here are a couple of tested frames with some neat tricks thrown in:
Expand|Select|Wrap|Line Numbers
  1. #Boa:Frame:Frame1
  2.  
  3. import wx
  4. import Frame2
  5.  
  6. def create(parent):
  7.     return Frame1(parent)
  8.  
  9. [wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1PANEL1, 
  10. ] = [wx.NewId() for _init_ctrls in range(3)]
  11.  
  12. class Frame1(wx.Frame):
  13.     def _init_coll_boxSizer1_Items(self, parent):
  14.         # generated method, don't edit
  15.  
  16.         parent.AddWindow(self.panel1, 1, border=0, flag=wx.EXPAND)
  17.  
  18.     def _init_sizers(self):
  19.         # generated method, don't edit
  20.         self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)
  21.  
  22.         self._init_coll_boxSizer1_Items(self.boxSizer1)
  23.  
  24.         self.SetSizer(self.boxSizer1)
  25.  
  26.     def _init_ctrls(self, prnt):
  27.         # generated method, don't edit
  28.         wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(110, 110),
  29.                 size=wx.Size(400, 250), style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
  30.         self.SetClientSize(wx.Size(392, 223))
  31.  
  32.         self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self, pos=wx.Point(0, 0),
  33.                 size=wx.Size(392, 223), style=wx.TAB_TRAVERSAL)
  34.  
  35.         self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='button1', name='button1',
  36.                 parent=self.panel1, pos=wx.Point(168, 96), size=wx.Size(75, 23), style=0)
  37.         self.button1.Bind(wx.EVT_BUTTON, self.OnButton1, id=wxID_FRAME1BUTTON1)
  38.  
  39.         self._init_sizers()
  40.  
  41.     def __init__(self, parent):
  42.         self._init_ctrls(parent)
  43.         self.childFrame = Frame2.Frame2(self)
  44.  
  45.     def OnButton1(self, event):
  46.         pos = self.GetPosition()
  47.         self.childFrame.Move(pos)
  48.         self.childFrame.Show()
  49.         self.Hide()
  50.  
Expand|Select|Wrap|Line Numbers
  1. #Boa:Frame:Frame2
  2.  
  3. import wx
  4.  
  5. def create(parent):
  6.     return Frame2(parent)
  7.  
  8. [wxID_FRAME2, wxID_FRAME2BUTTON1, wxID_FRAME2PANEL1, 
  9. ] = [wx.NewId() for _init_ctrls in range(3)]
  10.  
  11. class Frame2(wx.Frame):
  12.     def _init_coll_boxSizer1_Items(self, parent):
  13.         # generated method, don't edit
  14.  
  15.         parent.AddWindow(self.panel1, 1, border=0, flag=wx.EXPAND)
  16.  
  17.     def _init_sizers(self):
  18.         # generated method, don't edit
  19.         self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)
  20.  
  21.         self._init_coll_boxSizer1_Items(self.boxSizer1)
  22.  
  23.         self.SetSizer(self.boxSizer1)
  24.  
  25.     def _init_ctrls(self, prnt):
  26.         # generated method, don't edit
  27.         wx.Frame.__init__(self, id=wxID_FRAME2, name='Frame2', parent=prnt, pos=wx.Point(132, 132),
  28.                 size=wx.Size(400, 250), style=wx.DEFAULT_FRAME_STYLE, title='Frame2')
  29.         self.SetClientSize(wx.Size(392, 223))
  30.  
  31.         self.panel1 = wx.Panel(id=wxID_FRAME2PANEL1, name='panel1', parent=self, pos=wx.Point(0, 0),
  32.                 size=wx.Size(392, 223), style=wx.TAB_TRAVERSAL)
  33.  
  34.         self.button1 = wx.Button(id=wxID_FRAME2BUTTON1, label='button1', name='button1',
  35.                 parent=self.panel1, pos=wx.Point(144, 88), size=wx.Size(75, 23), style=0)
  36.         self.button1.Bind(wx.EVT_BUTTON, self.OnButton1, id=wxID_FRAME2BUTTON1)
  37.  
  38.         self._init_sizers()
  39.  
  40.     def __init__(self, parent):
  41.         self._init_ctrls(parent)
  42.         self.parent = parent
  43.  
  44.     def OnButton1(self, event):
  45.         pos = self.GetPosition()
  46.         self.parent.Move(pos)
  47.         self.parent.Show()
  48.         self.Hide()
  49.  
Sep 22 '07 #3
Thank you very much, i really appreciate the help....The code did work and I did see the Frame 2....But I also discovered MDI frames so I will try to impliment the whole thing in it...But still thank for the help....

Later
Apoorva
Sep 24 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Equis Uno | last post: by
4 posts views Thread by Simon Erikson | last post: by
19 posts views Thread by Grant Edwards | last post: by
8 posts views Thread by Erik Johnson | last post: by
2 posts views Thread by dr_tyson | last post: by
2 posts views Thread by rodmc | last post: by
22 posts views Thread by Glurt Wuntal | last post: by
reply views Thread by Robin Dunn | last post: by
16 posts views Thread by Andrea Gavana | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.