473,657 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxpython frame question

5 New Member
Hi I am using wxpython to develop my GUI. I have 3 frame. On the first frame I have ok button and when I click that it will open 2nd frame. And when I click ok button on 2nd frame, it will open 3rd frame. But I want my 2nd frame to be closed when I open the 3rd frame. I tried self.Close() it closes 2nd and 3rd frame.
I am attaching my code. Please help

Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import os, sys
  3. import string
  4. import re
  5. import cfgparse
  6. import cmd
  7. import  wx.lib.dialogs
  8. import pyExcelerator as xl
  9.  
  10. class Frame1(wx.Frame):
  11.         def __init__(self, parent, id, title):
  12.             wx.Frame.__init__(self, parent,-1,title,wx.DefaultPosition,wx.Size(300,150))
  13.             self.SetIcon(wx.Icon('PyCrust.ico',wx.BITMAP_TYPE_ICO))
  14.             self.mainpa = wx.Panel(self,-1,wx.DefaultPosition, wx.DefaultSize)
  15.  
  16.             Ok = wx.Button(self.mainpa, -1, 'Ok',wx.Point(50,50))
  17.             self.Bind(wx.EVT_BUTTON,self.OnOk,Ok)
  18.  
  19.         def OnOk(self,event):
  20.                 self.dlg1 = Frame2(self,-1)
  21.                 self.dlg1.Show(True)
  22.  
  23.  
  24. class Frame2(wx.Frame):
  25.     def __init__(self, parent, id, title = "Frame2"):
  26.             wx.Frame.__init__(self, parent,-1,title,wx.DefaultPosition,wx.Size(300,150))
  27.             self.SetIcon(wx.Icon('PyCrust.ico',wx.BITMAP_TYPE_ICO))
  28.             self.mainpa = wx.Panel(self,-1,wx.DefaultPosition, wx.DefaultSize)
  29.  
  30.             Ok = wx.Button(self.mainpa, -1, 'Ok',wx.Point(50,50))
  31.             self.Bind(wx.EVT_BUTTON,self.OnOk,Ok)
  32.  
  33.     def OnOk(self,event):
  34.         self.dlg2 = Frame3(self,-1)
  35.         self.dlg2.Show(True)
  36.  
  37. class Frame3(wx.Frame):
  38.     def __init__(self, parent, id, title = "Frame3"):
  39.             wx.Frame.__init__(self, parent,-1,title,wx.DefaultPosition,wx.Size(300,150))
  40.             self.SetIcon(wx.Icon('PyCrust.ico',wx.BITMAP_TYPE_ICO))
  41.             self.mainpa = wx.Panel(self,-1,wx.DefaultPosition, wx.DefaultSize)
  42.  
  43.             Ok = wx.Button(self.mainpa, -1, 'Ok',wx.Point(50,50))
  44.             self.Bind(wx.EVT_BUTTON,self.OnOk,Ok)
  45.  
  46.     def OnOk(self,event):
  47.         self.Close()
  48.  
  49.  
  50. class MyApp(wx.App):
  51.     def OnInit(self):
  52.         frame = Frame1(None, -1, 'Frame1')
  53.         frame.SetIcon(wx.Icon('PyCrust.ico',wx.BITMAP_TYPE_ICO))
  54.         frame.Show(True)
  55.         self.SetTopWindow(frame)
  56.         return True
  57.  
  58.  
  59. app = MyApp(0)
  60. app.MainLoop()
  61.  
Dec 14 '07 #1
4 4844
wrybread
5 New Member
You'd probably have more luck getting a response if you mentioned what your code currently does, and how you want that to be different.
Jan 31 '08 #2
kaarthikeyapreyan
107 New Member
import wx

class frames(wx.App):

def myframe(self):

self.frame1 = wx.Frame(None, wx.ID_ANY, 'Main Frame',size=(30 0,150), style=wx.DEFAUL T_FRAME_STYLE)
self.frame1.Sho w()
Ok1 = wx.Button(self. frame1, -1, 'Ok',wx.Point(5 0,50))
self.Bind(wx.EV T_BUTTON,self.o k1,Ok1)


def ok1(self,event) :
self.frame2 = wx.Frame(None, wx.ID_ANY, 'sub Frame2',size=(3 00,150), style=wx.DEFAUL T_FRAME_STYLE)
self.frame2.Sho w()
Ok2 = wx.Button(self. frame2, -1, 'Ok2',wx.Point( 50,50))
#self.frame1.Cl ose() if u want to hide the first frame too
#del self.frame1 if u want to delete the object instance
self.Bind(wx.EV T_BUTTON,self.o k2,Ok2)

def ok2(self,event) :

self.frame3 = wx.Frame(None, wx.ID_ANY, 'sub Frame3',size=(3 00,150), style=wx.DEFAUL T_FRAME_STYLE)
self.frame3.Sho w()
Ok3 = wx.Button(self. frame3, -1, 'Ok3',wx.Point( 50,50))
self.frame2.Clo se()
del self.frame2
self.Bind(wx.EV T_BUTTON,self.o k3,Ok3)

def ok3(self,event) :
print 'Button 3 clicked'

obj = frames(0)
obj.myframe()
obj.MainLoop()
Jan 31 '08 #3
kaarthikeyapreyan
107 New Member
Try This hope this will suit ur purpose.Am a Wx beginner hoping a lot more interaction from u guys

thanks
Jan 31 '08 #4
Elias Alhanatis
56 New Member
Maybe you can just add this line in your code.....

def OnOk(self,event ):
self.dlg2 = Frame3(self,-1)
self.dlg2.Show( True)
self.Show(False ) <----------- Add this

and the second Frame will hide when you open the third...
Jan 31 '08 #5

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

Similar topics

1
5985
by: wang xiaoyu | last post by:
Hello: i want use activex in wxpython program,but when i use MakeActiveXClass an exception occurs. this is my source code dealing the DICOM ocx.I must note that in this program "hwtxcontrol" is a ocx developed my me use vc6,this ocx works fine in wxpython. but you can see i only change this ocx with a new DICOM ocx and set up eventClass,
6
4548
by: Jive Dadson | last post by:
I'm trying (without conspicuous success) to start learning wxPython. Sooo... I opened the doc page wxPythonManual.html#wxpython-overview. The very first example does not work. Try it. I find much of what follows to be incomprehensible. Is there a good tutorial for novices? Here's the example that does not work. ("No module named frame") import wx
5
1420
by: Jared Russell | last post by:
I've recently decided to try my hand at GUI programming with wxPython, and I've got a couple questions about the general conventions regarding it. To mess around with it, I decided to create a small app to check my Gmail. I want something that will just sit in my system tray checking for new emails every ten minutes or so. As such, I have no need for an actual window anywhere. So I'm wondering if I should still use a Frame or not. ...
6
2753
by: rbann11 | last post by:
Hi, I am looking for example code that consists of just a frame and a grid(10x2). The grid must fill the its parent even if the frame is resized. Thanks in advance, Roger
9
5539
by: zxo102 | last post by:
Hi everyone, I am using a python socket server to collect data from a socket client and then control a image location ( wxpython) with the data, i.e. moving the image around in the wxpython frame. But the "app.MainLoop()" in wxpython looks like conflicting with the "while 1:" in socket server. After I commented the "app.MainLoop()", everything is working except two things: 1. if I click anywhere on the screen with the mouse, the image is...
9
4423
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the "Run" button, the GUI would close, and the 12 input variables would then be available for the rest of the program. So far, what I have been able to do is mostly a reverse engineering job to get the frame to look right and return the text variable...
1
1633
by: mark.martinez2 | last post by:
This is a wxPython question.. the wxPython group is pretty much inactive. I have an MDI parent frame and child frame set up. In the child frame, I want to use part of the frame to display the output from a .py that is mainly matplotlib (a graph) in a section of the frame. How can I get it to automatically run that script and place the resultant graph in a panel? Thanks
4
1924
by: Jimmy | last post by:
Hi, wxPython is cool and easy to use, But I ran into a problem recently when I try to write a GUI. The thing is I want to periodically update the content of StatixText object, so after create them, I pack them into a list...the problem comes when I later try to extract them from the list! I don't know why? my code is as following: import wx, socket import thread
0
1809
by: Stef Mientki | last post by:
Peter Anderson wrote: In PyScripter, you should run wxPython in the plain remote machine (not the wxPython remote), and you should set "reset before run flag" or reset the remote machine each time yourself. cheers, Stef
0
8385
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
8821
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
8723
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
8602
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
7316
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
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
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.