我怎样才能在这个WXPython程序上再加上3个按钮

我怎样才能在这个WXPython程序上再加上3个按钮,python,button,wxpython,Python,Button,Wxpython,我是WXPython的新编程人员,我从互联网上获取了这个程序,开始编写一个可视化程序 但是我怎样才能在这个程序上再加3个按钮而不出错呢 import wx class Panel1(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) try: image_file = "roses.jpg" bmp1 =

我是WXPython的新编程人员,我从互联网上获取了这个程序,开始编写一个可视化程序

但是我怎样才能在这个程序上再加3个按钮而不出错呢

import wx
class Panel1(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        try:
            image_file = "roses.jpg"
            bmp1 = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
            self.bitmap1 = wx.StaticBitmap(self, -1, bmp1, (0, 0))
            def InitUI(self):    


                str1 = "%s  %dx%d" % (image_file, bmp1.GetWidth(), bmp1.GetHeight()) 
                parent.SetTitle(str1)
        except IOError:
            print "Image file %s not found" % imageFile
            raise SystemExit
        self.button1 = wx.Button(self.bitmap1, id=-1, label='Snake', pos=(200, 300))

app = wx.PySimpleApp()
frame1 = wx.Frame(None, -1, "An image on a panel", size=(640, 480))
panel1 = Panel1(frame1, -1)
frame1.Show(True)
app.MainLoop()

我试过这个代码,但它对我不起作用。它给了我一个错误“分段错误”

使用
self.bitmap1
作为按钮的父项对我来说似乎很奇怪,所以我尝试使用
self
(Panel1)作为父项,它对我很有效

我做了一些其他修改-我添加了
self.
到一些变量中,我添加了
self.parent
。我移动了
InitUI

#!/usr/bin/env python

import wx

class Panel1(wx.Panel):

    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)

        self.parent = parent

        try:
            self.image_file = "roses.jpg"
            self.bmp1 = wx.Image(self.image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
            self.bitmap1 = wx.StaticBitmap(self, -1, self.bmp1, (0, 0))
        except IOError:
            print "Image file %s not found" % self.image_file
            raise SystemExit

        self.InitUI()

        self.button1 = wx.Button(self, id=-1, label='Snake', pos=(200, 300))
        self.button2 = wx.Button(self, id=-1, label='Apple', pos=(100, 100))

    def InitUI(self):    
        str1 = "%s  %dx%d" % (self.image_file, self.bmp1.GetWidth(), self.bmp1.GetHeight()) 
        self.parent.SetTitle(str1)

app = wx.PySimpleApp()
frame1 = wx.Frame(None, -1, "An image on a panel", size=(640, 480))
panel1 = Panel1(frame1, -1)
frame1.Show(True)
app.MainLoop()

对不起,问题的标题有误。这只是一个程序。你有什么错误?总是对完整的错误信息提出疑问。问题是我没有错误。我只想再添加3个按钮,但我不知道如何添加。
wx.pysimpleap
已被弃用。您应该使用
wx.App(False)
。至于添加更多的按钮,只需创建更多的按钮实例并更改位置,使它们不相互重叠(或使用大小调整器)