wxpython: how do i write this without the id parameter?

John Salerno johnjsal at NOSPAMgmail.com
Mon Jun 12 16:50:40 EDT 2006


I was reading in the wxPython wiki that most of the time you don't have 
to include the id parameter at all, and you can just use keyword 
arguments for other parameters. But I'm having trouble converting this 
code into that method (i.e., without the id parameter). I keep getting 
errors that involve wrong parameters, or that they are out of order, 
etc. So I'm hoping someone can show me how to re-write the constructors 
for InputForm and wx.Frame, as well as the __init__ method, so that they 
will just deal with parent and title.

Also, the two buttons have an id parameter, but leaving them out doesn't 
seem to create any problems.

Thanks.

-----------

import wx


class InputForm(wx.Frame):

     def __init__(self, parent, id, title):
         wx.Frame.__init__(self, parent, id, title)

         panel = wx.Panel(self)
         self.btnOK = wx.Button(panel, label='OK')
         self.btnCancel = wx.Button(panel, label='Cancel')

         sizer = wx.BoxSizer(wx.HORIZONTAL)
         sizer.Add(self.btnOK, 0, wx.ALL, 10)
         sizer.Add(self.btnCancel, 0, wx.ALL, 10)
         panel.SetSizer(sizer)


class MyApp(wx.App):

     def OnInit(self):
         frame = InputForm(None, -1, title='Data Entry Form')
         self.SetTopWindow(frame)
         frame.Show()
         return True


app = MyApp(redirect=False)
app.MainLoop()



More information about the Python-list mailing list