June 28th, 2004, 05:16 AM
wxPython : Returning values from frames
I need some help please.
I am writing wxPython app, that must have some initialization values.
In the beginning of the main frame(frame1), it checkes whether those values exist, if not it should run a separate process (frame2),
that its end result is a returned value to the main frame(frame1).
I am having problems achieving that.
I was able to run frame2 from frame1, but I couldn't returned any results to frame 1
and also frame1 didn't stop, it continued executing in parallel to frame2.
I attched some code that might explain the problem more clearly ,as you can see in the attached code, frame1 has a function "GetClientID" that suppose to execute frame2, until a valid value is returned ( or until the user chooses to exit)
Thank you very much for the help.
frame 1 is:
from wxPython.wx import *
# frame initialization
wxFrame.__init__(self, NULL, -1, "dc",
# get client ID
self.ClientID = self.GetClientID()
# Supposed to run frame 2 , and continue running
it until a valid value is returned
frame = MyWin()
if __name__ == '__main__':
app = MyApp(0)
def __init__(self, parent, id):
wxPanel.__init__(self, parent, id)
l1 = wxStaticText(self, -1, "Please enter your email:",(20, 20))
self.t1 = wxTextCtrl(self, 1, "",(150, 20), size=(125, -1))
l2 = wxStaticText(self, -1, "Please enter password:",(20, 70))
self.t2 = wxTextCtrl(self, 2, "",(150, 70), size=(125, -1))
btn = wxButton(self, -1, "Click here", (170, 150))
self.Bind(EVT_BUTTON, self.OnClick, btn)
def OnClick(self, evt):
# Read input values,
# do some validation
# and some processing and return result
app = wxPySimpleApp()
frame = wxFrame(None,-1,"TITLE",wxDefaultPosition, wxSize(480,280))
x = MainWindow(frame, -1)
June 28th, 2004, 06:10 AM
The simple solution is to withdraw the main application window Show(false) and and make your second frame a wxDialog derived window. If you make it a modal dialog you can create the dialog and query its values before destroying it.
Maybe the standard dialog is enough:
dlg = wxTextEntryDialog(self, 'EMAIL','Please enter your email address', 'email@example.com')
if dlg.ShowModal() == wxID_OK:
June 28th, 2004, 04:10 PM
Thank you for your quick reply.
Well, this is what I did, but since I want the user to type in more then 1 field, i'll need more then one wxDialog.
so input form is a great choice, but as I mentioned before,
when i'm calling the input form from within the main program,
the main program doesn't stop and wait for the returned values from the input form,
Originally Posted by Grim Archon
June 28th, 2004, 04:36 PM
It is not difficult to create your own dialogs with as many fields as you like. Simply create a class based on wxDialog then in it's __init__ create as many entry widgets as you need.
Then you define a method that returns the values of the fields.
Are you using BOA? That has the ability to design new dialogs with your assistance. (The constructor anyway). The only bit you need to do by hand is to define the "get values" method.
I am not sure what you mean by the program not waiting - if you use the ShowModal then any other window will not get focus.
IM/PM if you need more info.
June 30th, 2004, 10:54 PM
Thank you Grim.
I did as you suggested and it's working great.