472,981 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,981 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 6178
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

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

Similar topics

3
by: Equis Uno | last post by:
Hi, I'm trying to run some Python software I downloaded off of sf.net. It's called Boa. It uses wxPython. It appears my install of Python cannot see my install of wxPython.
4
by: Simon Erikson | last post by:
Hello: I would like to build an app consisting of a "root" frame that can contain an arbitrary number of child frames (the user will click to create them). Each of these child frames needs the...
19
by: Grant Edwards | last post by:
I've decided to learn wxPython, and I'm afraid I just don't grok the whole "id" thing where you have to pull unique integers out of your, er, the air and then use those to refer to objects: ...
8
by: Erik Johnson | last post by:
I am looking for some input on GUI libraries. I want to build a Python-driven GUI, but don't really understand the playing field very well. I have generally heard good things about wxPython. I...
2
by: dr_tyson | last post by:
I am trying to embed images into a wxPython app (created using Boa Constructor), but have not been able to do so. I know how to embed plots, but images seem to be a problem. I've tried using code...
2
by: rodmc | last post by:
I am totally new to Python and WxPython and need to write an application which can open up an external windows from a plug-in within GAIM (using pyGAIM). I have managed to hack some code together...
22
by: Glurt Wuntal | last post by:
I am a newbie with Python. It's a great language, but I would like to be able to present a simple gui menu for some of my scripts; something better than using 'raw_input' prompts. Any...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
16
by: Andrea Gavana | last post by:
Hi Diez & All, Do you mind explaining "why" you find it *buttugly*? I am asking just out of curiosity, obviously. I am so biased towards wxPython that I won't make any comment on this thread...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.