문제

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

도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top