按钮事件的WXpython绑定对象

时间:2014-05-12 14:14:06

标签: python events button wxpython wxwidgets

我正在使用wxpython为一个软件创建一个前端,我遇到的问题是我无法让evt_button工作时间我打开脚本会自动关闭窗口。它不会给出任何错误消息或警告。

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"

这个问题显然是有约束力的,但我没有看到或理解的是为什么

1 个答案:

答案 0 :(得分:1)

我认为你非常接近它。

只需更改

self.Bind(wx.EVT_BUTTON,self.onclick,button1)

self.button1.Bind(wx.EVT_BUTTON, self.onclick)

self.Bind(wx.EVT_BUTTON, self.onclick, self.button1)
相关问题