By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,939 Members | 1,602 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,939 IT Pros & Developers. It's quick & easy.

wxpython frame question

P: 5
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
Share this Question
Share on Google+
4 Replies


P: 5
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
100+
P: 107
import wx

class frames(wx.App):

def myframe(self):

self.frame1 = wx.Frame(None, wx.ID_ANY, 'Main Frame',size=(300,150), style=wx.DEFAULT_FRAME_STYLE)
self.frame1.Show()
Ok1 = wx.Button(self.frame1, -1, 'Ok',wx.Point(50,50))
self.Bind(wx.EVT_BUTTON,self.ok1,Ok1)


def ok1(self,event):
self.frame2 = wx.Frame(None, wx.ID_ANY, 'sub Frame2',size=(300,150), style=wx.DEFAULT_FRAME_STYLE)
self.frame2.Show()
Ok2 = wx.Button(self.frame2, -1, 'Ok2',wx.Point(50,50))
#self.frame1.Close() if u want to hide the first frame too
#del self.frame1 if u want to delete the object instance
self.Bind(wx.EVT_BUTTON,self.ok2,Ok2)

def ok2(self,event):

self.frame3 = wx.Frame(None, wx.ID_ANY, 'sub Frame3',size=(300,150), style=wx.DEFAULT_FRAME_STYLE)
self.frame3.Show()
Ok3 = wx.Button(self.frame3, -1, 'Ok3',wx.Point(50,50))
self.frame2.Close()
del self.frame2
self.Bind(wx.EVT_BUTTON,self.ok3,Ok3)

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

obj = frames(0)
obj.myframe()
obj.MainLoop()
Jan 31 '08 #3

kaarthikeyapreyan
100+
P: 107
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
P: 56
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

Post your reply

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