This should be a pretty easy question but I can't really find any docs or examples on how to do this. I'm just trying to learn wxPython here so this code is very amatuerish, generated using wxglade. I've basically got two frames, one which asks the questions, another which displays the answers but the variables from the first frame don't work in the second. I'm pretty new to python as well so...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Mon Jun 9 20:06:46 2008
import wx
# begin wxGlade: extracode
# end wxGlade
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.label_1 = wx.StaticText(self, -1, "Number")
self.spin_ctrl_1 = wx.SpinCtrl(self, -1, "", min=0, max=1000)
self.label_2 = wx.StaticText(self, -1, "Text")
self.text_ctrl_1 = wx.TextCtrl(self, -1, "Enter some text")
self.label_3 = wx.StaticText(self, -1, "Yes or No?")
self.radio_btn_1 = wx.RadioButton(self, -1, "Yes")
self.radio_btn_2 = wx.RadioButton(self, -1, "No")
self.label_4 = wx.StaticText(self, -1, "Click")
self.button_1 = wx.Button(self, -1, "Submit Everything!")
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_TEXT_ENTER, self.OnSubmit, self.text_ctrl_1)
self.Bind(wx.EVT_BUTTON, self.OnSubmit, self.button_1)
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("Some Questions...")
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
grid_sizer_1 = wx.GridSizer(4, 2, 0, 0)
sizer_2 = wx.BoxSizer(wx.VERTICAL)
grid_sizer_1.Add(self.label_1, 0, 0, 0)
grid_sizer_1.Add(self.spin_ctrl_1, 0, 0, 0)
grid_sizer_1.Add(self.label_2, 0, 0, 0)
grid_sizer_1.Add(self.text_ctrl_1, 0, 0, 0)
grid_sizer_1.Add(self.label_3, 0, 0, 0)
sizer_2.Add(self.radio_btn_1, 0, 0, 0)
sizer_2.Add(self.radio_btn_2, 0, 0, 0)
grid_sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
grid_sizer_1.Add(self.label_4, 0, 0, 0)
grid_sizer_1.Add(self.button_1, 0, 0, 0)
self.SetSizer(grid_sizer_1)
grid_sizer_1.Fit(self)
self.Layout()
# end wxGlade
def OnSubmit(self, event): # wxGlade: MyFrame.<event_handler>
NumberValue = self.spin_ctrl_1.GetValue()
TextValue = self.text_ctrl_1.GetValue()
YesValue = self.radio_btn_1.GetValue()
NoValue = self.radio_btn_2.GetValue()
if YesValue == True:
YesNo = "Yes"
else:
YesNo = "No"
print "Number: %s\nText: %s\nYes or No: %s" %(NumberValue,TextValue,YesNo)
self.Close()
MyFrame2(None, -1, "").Show()
event.Skip()
# end of class MyFrame
class MyFrame2(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.label_5 = wx.StaticText(self, -1, "Number")
self.label_9 = wx.StaticText(self, -1, NumberValue)
self.label_6 = wx.StaticText(self, -1, "Text")
self.label_8 = wx.StaticText(self, -1, TextValue)
self.label_7 = wx.StaticText(self, -1, "Yes or No?")
self.label_10 = wx.StaticText(self, -1, YesNo)
self.button_2 = wx.Button(self, wx.ID_CLOSE, "", style=wx.BU_RIGHT)
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_BUTTON, self.OnClose, self.button_2)
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("frame_2")
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
grid_sizer_2 = wx.GridSizer(4, 2, 0, 0)
grid_sizer_2.Add(self.label_5, 0, 0, 0)
grid_sizer_2.Add(self.label_9, 0, 0, 0)
grid_sizer_2.Add(self.label_6, 0, 0, 0)
grid_sizer_2.Add(self.label_8, 0, 0, 0)
grid_sizer_2.Add(self.label_7, 0, 0, 0)
grid_sizer_2.Add(self.label_10, 0, 0, 0)
sizer_1.Add(grid_sizer_2, 1, wx.EXPAND, 0)
sizer_1.Add(self.button_2, 0, 0, 0)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
self.Layout()
# end wxGlade
def OnClose(self, event): # wxGlade: MyFrame.<event_handler>
self.Close()
event.Skip()
# end of class MyFrame2
if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()
Thanks for your time