Closing and opening frames in wxPython
I am working on writing a very simple client / server application as an excuse to start learning web / gui programming in python. At the moment, I am stuck moving from my login frame to the main application frame.
The login fragment is a subclass of wx.Frame and basically I just want to close it and open the main frame when it gets an acknowledgment from the server:
def handleServerSignon(self, msg):
if msg.getCode() == net.message.HANDLE_IN_USE:
self.status.SetStatusText('Handle already in use')
elif msg.getCode() == net.message.SIGNON_SUCCESSFUL:
self.Close()
mainWindow = wx.Frame(None, wx.ID_ANY, 'main window', wx.DefaultPosition, \
(640, 480))
mainWindow.Show(True)
I can't even get this to give a consistent error message though ... sometimes it works, sometimes it crashes with the following:
python: ../../ src / xcb_io.c: 242: process_responses: Assertion `(((long) (dpy-> last_request_read) - (long) (dpy-> request)) <= 0) 'failed.
Any help is greatly appreciated!
Walker
I would make your main frame and then show a modal login dialog instead.
If you don't want to do this, I suggest you create two separate frames and ask the application to listen for the close event in the login frame. Handle the login in this event handler and then display the main window. Basically, you don't want to instantiate the main window in your event handler, because after you leave this function, the scope is lost, the garbage collector will try to delete your frame.
Finally, you should consider calling getCode()
once and caching the result for your comparisons. Since your if statement and elif statement are named getCode()
, it can give different results very well.
a source to share