【发布时间】:2015-11-28 16:02:26
【问题描述】:
我是 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()
【问题讨论】:
-
抱歉题主有误。这只是一个程序。
-
你有什么错误?始终提出完整的错误消息。
-
问题是我没有错误。我只想再添加 3 个按钮,但我不知道怎么做。
-
wx.PySimpleApp已弃用。你应该使用wx.App(False)。至于添加更多按钮,只需创建更多按钮实例并更改位置,使它们不会彼此重叠(或使用大小调整器)