I've been trying to create a little python GUI for a database I'm writing. My main GUI works, but a dialog I've created for data entry throws the above error whenever the buttons are clicked (the rest of the GUI seems to work).
A cut down version of the code is below:
class AddDialog(wx.Dialog)
def __init__(self, *args, **kw)
super(AddDialog, self).__init__(*args, **kw)
self.InitUI()
self.SetSize((300,300))
self.SetTitle('Add')
def InitUI(self):
panel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
st = wx.StaticText(panel, label = 'Example')
vbox.Add(st, flag = wx.ALIGN_CENTRE, border = 5)
closeButton = wx.Button(self, label = "Close")
vbox.Add(closerButton)
self.SetSizer(vbox)
closeButton.Bind(wx.EVT_BUTTON, self.OnClose)
def OnClose():
self.Destroy()
The error message that I get is:
TypeError: OnClose() takes no arguments(2 given)
However, I don't think I'm giving it any arguments. Can anyone help this beginner in working out what python doesn't like?
Thanks in advance
When you do this:
you are creating a link, where if the user clicks a button, the window will receive an EVT_BUTTON event, and your function OnClose will be called. It will call it with two arguments - self (which is true for any class function) and the event itself. You just need to change your function header to look like this:
and then it should work.