我是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
相关问题 更多 >
编程相关推荐