wxTextCtrl giving an error

Hey guys,

I’m working on learning some wxPython basics, and I’m running up against an issue that I haven’t been able to decipher. Here’s my code:

class PasswordPanel(wx.Dialog):
def init(self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE):
self.sizer1 = wx.BoxSizer(wx.VERTICAL)
self.buttonSizer= wx.StdDialogButtonSizer()

    self.dlg1 = wx.TextCtrl(self, -1, "Enter Username:", "", size=(80,-1))
    self.dlg2 = wx.TextCtrl(self, -1, "Enter Password:", "", style=wx.TE_PASSWORD, size=(80,-1))
    self.submit = wx.Button(self, "Submit", wx.ID_OK)
    self.cancel = wx.Button(self, "Cancel", wx.ID_CANCEL)

   
    self.sizer1.Add(self.dlg1, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    self.sizer1.Add(self.dlg2, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    self.buttonSizer.AddButton(self.submit)
    self.buttonSizer.AddButton(self.cancel)
    self.buttonSizer.Realize()
   
    self.sizer1.Add(self.buttonSizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
   
    self.SetSizer(self.sizer1)
    self.sizer1.Fit(self)
   
    self.ShowModal(True)

This is my output:

bt Ticketing_System # python main.py
Traceback (most recent call last):
File “main.py”, line 68, in InitializeConnection
self.passwordDialog = PasswordPanel(self, -1, “User Authentication”)
File “main.py”, line 75, in init
self.dlg1 = wx.TextCtrl(self, -1, “Enter Username:”, “”, size=(80,-1))
File “/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_controls.py”, line 1691, in init
controls.TextCtrl_swiginit(self,controls.new_TextCtrl(*args, **kwargs))
TypeError: in method ‘new_TextCtrl’, expected argument 1 of type ‘wxWindow *’

This seems to be saying that it is not receiving parent window information? Or I am totally off? Any help on what I’m missing would be appreciated.

Jason

Jason Conner wrote:

Hey guys,

I'm working on learning some wxPython basics, and I'm running
up against an issue that I haven't been able to decipher.
Here's my code:

class PasswordPanel(wx.Dialog):
    def __init__(self, parent, ID, title,
size=wx.DefaultSize, pos=wx.DefaultPosition,
style=wx.DEFAULT_DIALOG_STYLE):
        self.sizer1 = wx.BoxSizer(wx.VERTICAL)
        self.buttonSizer= wx.StdDialogButtonSizer()
        
        self.dlg1 = wx.TextCtrl(self, -1, "Enter Username:",
"", size=(80,-1))
        self.dlg2 = wx.TextCtrl(self, -1, "Enter Password:",
"", style=wx.TE_PASSWORD, size=(80,-1))

You need to initialise wx.Dialog. After def __init__(...), insert the
following -
    wx.Dialog.__init__(self, parent, ID, title, size=size, pos=pos,
style=style)

This is how Python works. If you create a subclass and override __init__(),
it does not automatically call __init__() on the main class - it is up to
you to call it explicitly.

Also, in your wx.TextCtrl constructors, I notice an extra "" after passing
the initial value. I don't think this is valid, so after overcoming the
first problem you may hit another one. If so, remove the "" and see if it
works then.

HTH

Frank Millman