【发布时间】:2014-03-19 09:25:24
【问题描述】:
我在 Windows 7 操作系统上使用 python v2.7 和 wxPython v3.0。在我的应用程序中,我有一个名为myPanel 的面板。我在myPanel 上有一个图像作为背景,图像名称是green.bmp myPanel 包含一个名为myButton 的按钮。这个myButton 还包含一个名为blue.bmp 的图像作为背景
问题:当我执行我的代码时,我在myPanel 上看不到myButton。我无法弄清楚为什么它不起作用。任何帮助将不胜感激。 如果我不使用图像作为myPanel 的背景,那么myButton 是可见的!
代码:图片可以从这里Green.bmp和Blue.bmp下载。下面提供代码sn-p:
import wx
class gui(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, None, id, title, size=(500,400))
myPanel = wx.Panel(self, -1, size=(300,200))
image_file1 = 'green.bmp'
image1 = wx.Image(image_file1, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
#---- Comment out the line below then the button is visible
self.bitmap2 = wx.StaticBitmap(myPanel, -1, image1, (0, 0))
myButton = wx.Button(myPanel, -1, size =(30,30), pos=(20,20))
image_file2 = 'blue.bmp'
image2 = wx.Image(image_file2, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.bitmap1 = wx.StaticBitmap(myButton, -1, image2, (0, 0))
if __name__=='__main__':
app = wx.App()
frame = gui(parent=None, id=-1, title="Test")
frame.Show()
app.MainLoop()
感谢您的宝贵时间!
【问题讨论】:
标签: python python-2.7 user-interface wxpython