Reputation: 467
I' working with wxpython to create a front end for a piece of software, the issue I am have is I can't get the evt_button to work e vert time I open the script it automatically closes the window. it isnt giving any error messages or warnings.
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, 'form title', wx.DefaultPosition, (560, 472), style=wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.RESIZE_BORDER | 0 | 0 | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX)
self.panel = wx.Panel(self, -1)
self.button1 = wx.Button(self.panel, -1, 'button', (8,72), (75, 23))
self.button1.SetFont(wx.Font(8.25, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif'))
self.button1.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
self.Bind(wx.EVT_BUTTON,self.onclick,button1)
def onclick(self,event):
print "yay it works"
The issue is obviously the binding but what I'm not seeing or understanding is why
Upvotes: 0
Views: 3674
Reputation: 2710
I think you are very close to it.
Just change
self.Bind(wx.EVT_BUTTON,self.onclick,button1)
to either
self.button1.Bind(wx.EVT_BUTTON, self.onclick)
or
self.Bind(wx.EVT_BUTTON, self.onclick, self.button1)
Upvotes: 1