Check out the code below.
It creates MyFrame the first time through. When the "close me" button is
selected, then MyFrame posts a "MyEvent" to the app, which closes MyFrame
and creates/shows MyFrame2.
The code is pretty simple to follow.
HTH,
jw
# begin code
from wxPython.wx import *
# First create an ID for your custom event
EVT_MYEVENT_ID = wxNewEventType()
# Next, provide a "hook" for your event (not sure of the proper name)
def EVT_MYEVENT(win, func):
win.Connect(-1, -1, EVT_MYEVENT_ID, func)
# Finally, create the actual event object.
class MyEvent( wxPyCommandEvent ):
def __init__(self, id):
wxPyCommandEvent.__init__( self, EVT_MYEVENT_ID, id )
# Now two separate frames. The first one below will fire the custom
# event
class MyFrame( wxFrame ):
def __init__( self ):
wxFrame.__init__( self, None, -1, "Test" )
self.SetSize( wxSize( 240, 240 ) )
self.SetBackgroundColour( wxRED )
btn = wxButton( self, 1212, "Close me" )
EVT_BUTTON( self, 1212, self.on_close_me )
self.Centre()
def on_close_me( self, e ):
# Close the window, and post our custom event
self.Close( true )
evt = MyEvent( self.GetId() )
app = wxGetApp()
app.ProcessEvent( evt )
class MyFrame2( wxFrame ):
def __init__( self ):
wxFrame.__init__( self, None, -1, "Test Frame two" )
self.SetSize( wxSize( 240, 240 ) )
self.Centre()
class MyApp( wxApp ):
def OnInit( self ):
self.frame = MyFrame()
self.frame.Show( true )
# Handle our custom event
EVT_MYEVENT( self, self.on_my_event )
return true
# Define the event handler for our custom event
def on_my_event( self, evt ):
self.frame.Close()
self.frame = MyFrame2()
self.frame.Show( true )
def main():
app = MyApp(0)
app.MainLoop()
if __name__ == "__main__":
main()
···
-----Original Message-----
From: Mike Wagman [mailto:mwagman@charter.net]
Sent: Tuesday, July 15, 2003 10:10 AM
To: wxpython list
Subject: RE: [wxPython-users] Managing two framesI need to input three lines of text, with two bing passwords that are
***'d over (which that I can do now)."If you have to use a wxFrame, you'll have to define a new event and
post it back to the app and handle it from the event handler"Ok how do I do that.