import wx
class MyPanel(wx.Panel):
def __init__(self, parent):
super(MyPanel, self).__init__(parent)
img = wx.Image('example.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.staticBitmap = wx.StaticBitmap(self, -1, img, pos=(10, 10))
btn1 = wx.Button(self, label='按钮1', pos=(10, 200))
btn2 = wx.Button(self, label='按钮2', pos=(120, 200))
btn1.Bind(wx.EVT_BUTTON, self.on_button1_clicked)
btn2.Bind(wx.EVT_BUTTON, self.on_button2_clicked)
def on_button1_clicked(self, event):
print("按钮1被点击")
def on_button2_clicked(self, event):
print("按钮2被点击")
class MyFrame(wx.Frame):
def __init__(self):
super(MyFrame, self).__init__(None, title='图片显示与按钮示例', size=(300, 300))
self.panel = MyPanel(self)
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame()
frame.Show()
app.MainLoop()