我正在开发一个测试台,在点击一个按钮时,将完成一个特定的测试,因此如果测试成功完成,则应该用彩色矩形表示。但问题是如何用一个按钮点击事件绑定2个事件。而且当我执行附加代码时,打开单击按钮,矩形不会显示在面板上。
import wx
class MyClass(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id, "GUI", size =(500,300))
panel=wx.Panel(self)
button=wx.Button(panel,label = 'Exit', pos = (250,180), size = (50,50))
button1=wx.Button(panel,label = 'Open', pos = (50,50), size = (50,50))
self.Bind(wx.EVT_PAINT, self.Rectangle,button1)
self.Bind(wx.EVT_BUTTON,self.CloseButton,button)
self.Bind(wx.EVT_CLOSE,self.CloseProgram)
def Rectangle(self,e):
dc = wx.PaintDC(self.panel)
dc.SetPen(wx.Pen('RED'))
dc.SetBrush(wx.Brush('BLUE'))
dc.DrawRectangle(130, 15, 90, 60)
def CloseButton(self,e):
self.Close(True)
def CloseProgram(self,e):
self.Destroy()
if __name__ == '__main__':
app=wx.App()
frame=MyClass(parent=None,id=-1)
frame.Show()
app.MainLoop()