I'm writing an application in wx Python that is supposed to get some values, entered into TextCtrl-boxes, and passing them on to a function as you press a start button. This has proven complicated.
This is the script:
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title=title,
size=(300, 200))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
panel = wx.Panel(self)
sizer = wx.GridBagSizer(4, 2)
text1 = wx.StaticText(panel, label="Set COM-ports")
sizer.Add(text1, pos=(0, 0), flag=wx.TOP|wx.LEFT|wx.BOTTOM,
border=15)
line = wx.StaticLine(panel)
sizer.Add(line, pos=(1, 0), span=(1, 5),
flag=wx.EXPAND|wx.BOTTOM, border=10)
text2 = wx.StaticText(panel, label="Dispersion control port:")
sizer.Add(text2, pos=(2, 0), flag=wx.ALIGN_RIGHT|wx.LEFT, border=10)
tc1 = wx.TextCtrl(panel)
sizer.Add(tc1, pos=(2, 1), flag=wx.LEFT, border=10)
text3 = wx.StaticText(panel, label="GPS port:")
sizer.Add(text3, pos=(3, 0),flag=wx.ALIGN_RIGHT|wx.LEFT, border=10)
tc2 = wx.TextCtrl(panel)
sizer.Add(tc2, pos=(3, 1), flag=wx.LEFT,border=10)
button4 = wx.Button(panel, label="Start")
DispPort=tc1.GetValue()
GpsPort=tc2.GetValue()
sizer.Add(button4, pos=(4, 0), flag=wx.ALIGN_RIGHT)
button4.Bind(wx.EVT_BUTTON, self.OnStart(self, event,DispPort,GpsPort))
button5 = wx.Button(panel, wx.ID_EXIT, label="Cancel")
sizer.Add(button5, pos=(4, 1), flag=wx.ALIGN_LEFT|wx.LEFT, border=10)
self.Bind(wx.EVT_BUTTON, self.OnQuitApp, id=wx.ID_EXIT)
panel.SetSizer(sizer)
def OnStart(self, event, DispPort, GpsPort):
stdial=Startclass(self,DispPort,GpsPort)
def OnQuitApp(self, event):
self.Close()
As you can see OnQuitApp() needs no arguments, not even parentheses, to be called. OnStart() on the other hand, needs arguments. The ones I'd like to include are DispPort and GpsPort. But writing
self.OnStart(DispPort,GpsPort)
does not work. Writing
self.OnStart(self, DispPort,GpsPort)
does not work either. Neither does
self.OnStart(self,event,DispPort,GpsPort)
The first has two few arguments, the second gets the arguments to be of the wrong type, the third uses the undefined variable 'event'.
Where do I go from here?