|
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 -
import wx
-
import os, sys
-
import string
-
import re
-
import cfgparse
-
import cmd
-
import wx.lib.dialogs
-
import pyExcelerator as xl
-
-
class Frame1(wx.Frame):
-
def __init__(self, parent, id, title):
-
wx.Frame.__init__(self, parent,-1,title,wx.DefaultPosition,wx.Size(300,150))
-
self.SetIcon(wx.Icon('PyCrust.ico',wx.BITMAP_TYPE_ICO))
-
self.mainpa = wx.Panel(self,-1,wx.DefaultPosition, wx.DefaultSize)
-
-
Ok = wx.Button(self.mainpa, -1, 'Ok',wx.Point(50,50))
-
self.Bind(wx.EVT_BUTTON,self.OnOk,Ok)
-
-
def OnOk(self,event):
-
self.dlg1 = Frame2(self,-1)
-
self.dlg1.Show(True)
-
-
-
class Frame2(wx.Frame):
-
def __init__(self, parent, id, title = "Frame2"):
-
wx.Frame.__init__(self, parent,-1,title,wx.DefaultPosition,wx.Size(300,150))
-
self.SetIcon(wx.Icon('PyCrust.ico',wx.BITMAP_TYPE_ICO))
-
self.mainpa = wx.Panel(self,-1,wx.DefaultPosition, wx.DefaultSize)
-
-
Ok = wx.Button(self.mainpa, -1, 'Ok',wx.Point(50,50))
-
self.Bind(wx.EVT_BUTTON,self.OnOk,Ok)
-
-
def OnOk(self,event):
-
self.dlg2 = Frame3(self,-1)
-
self.dlg2.Show(True)
-
-
class Frame3(wx.Frame):
-
def __init__(self, parent, id, title = "Frame3"):
-
wx.Frame.__init__(self, parent,-1,title,wx.DefaultPosition,wx.Size(300,150))
-
self.SetIcon(wx.Icon('PyCrust.ico',wx.BITMAP_TYPE_ICO))
-
self.mainpa = wx.Panel(self,-1,wx.DefaultPosition, wx.DefaultSize)
-
-
Ok = wx.Button(self.mainpa, -1, 'Ok',wx.Point(50,50))
-
self.Bind(wx.EVT_BUTTON,self.OnOk,Ok)
-
-
def OnOk(self,event):
-
self.Close()
-
-
-
class MyApp(wx.App):
-
def OnInit(self):
-
frame = Frame1(None, -1, 'Frame1')
-
frame.SetIcon(wx.Icon('PyCrust.ico',wx.BITMAP_TYPE_ICO))
-
frame.Show(True)
-
self.SetTopWindow(frame)
-
return True
-
-
-
app = MyApp(0)
-
app.MainLoop()
-
| |
Share:
|
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.
| | 100+ |
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()
| | 100+ |
Try This hope this will suit ur purpose.Am a Wx beginner hoping a lot more interaction from u guys
thanks
| | |
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...
| | Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
1 post
views
Thread by wang xiaoyu |
last post: by
|
6 posts
views
Thread by Jive Dadson |
last post: by
|
5 posts
views
Thread by Jared Russell |
last post: by
|
6 posts
views
Thread by rbann11 |
last post: by
|
9 posts
views
Thread by zxo102 |
last post: by
|
9 posts
views
Thread by Tyler |
last post: by
|
1 post
views
Thread by mark.martinez2 |
last post: by
|
4 posts
views
Thread by Jimmy |
last post: by
|
reply
views
Thread by Stef Mientki |
last post: by
| | | | | | | | | | |