473,770 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxPython Multiple Frames using Boa Constructor

12 New Member
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*******autog enerated 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 6217
bartonc
6,596 Recognized Expert Expert
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 Recognized Expert Expert
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
ApoorvaDesai
12 New Member
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
2822
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
4341
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 full functionality of a frame (title,menu,status bars, min,max,close icons, scroll bars, sizing, moving). In addition, the user must be able to create grandchild frames within these child frames, to an arbitrary depth (in practice limited to 10...
19
3429
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: From whe wxPython wiki examples: self.button =wxButton(self, 10, "Save", wxPoint(200, 325)) EVT_BUTTON(self, 10, self.OnClick)
8
4496
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 happen to already own John Grayson's book about Tkinter programming, so that is rather handy if I decide to use Tkinter. I have done some things slightly more involved than "Hello World" in Tkinter - I have never used wxPython. So, basically the...
2
3181
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 analogous to the example given at the Matplotlib website to no avail. If anybody has been successful at this could you please post some sample code? That would be greatly appreciated. Thanks! Randy
2
1712
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 from what little I have covered so far, however GAIM refuses to open until I have closed the extra window. I appreciate this is probably a simple point but I would be grateful for any advice people can offer on how I can make them both appear so...
22
5060
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 recommendations for a program that will allow me to create the gui screens? Something useable in Linux. thanks.
0
1662
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 version, many of which are listed below and at http://wxpython.org/recentchanges.php. What is wxPython?
16
2414
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 in particular, but I am curious to know why some people find it "ugly" or "bad" or whatever. It has its own bugs and missing features, of course, but it is one of the major GUI player in the arena, together with PyQt and PyGTK.
0
9595
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.