0

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

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

3 Comments

THanks for the help, I see what's happening there.
you are welcome! nice GUI library choice by the way!
And if you want to know what the difference is between those two bind methods, the wxPython wiki has a nice write-up: wiki.wxpython.org/self.Bind%20vs.%20self.button.Bind

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.