我一直在研究一个菜单界面,我希望在其中使用背景,然后将自定义图像用作按钮,但是无法显示它们
import wx
import pygame
import os
class menu(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Compsci Vs. Sheep: The Game',size=(640,640))#defining the properties of the window
MainPanel=wx.Panel(self)
image_file='main_screen.jpeg'
bmp=wx.Bitmap(image_file)
self.bitmap = wx.StaticBitmap(self, wx.ID_ANY, bmp, (0, 0))
PlayButton=wx.Bitmap('exit.jpeg', wx.BITMAP_TYPE_ANY)
self.PlayButton=wx.BitmapButton(self.bitmap, -1, PlayButton, pos=())
self.Bind=(wx.EVT_BUTTON, self.closeMe, self.PlayButton)
self.PlayButton.SetDefault()
self.Bind(wx.EVT_CLOSE,self.closecorner)
def closeMe(self,event):
self.Destroy()
def closecorner(self,event):
self.Destroy()
pygame.mixer.quit()#defining all events
if __name__=='__main__':
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
pygame.mixer.music.load("exorcist.ogg")
pygame.mixer.music.play(-1)
app=wx.PySimpleApp()
frame=menu(parent=None,id=-1)
frame.Show()
app.MainLoop()
任何人都可以解释为什么我不断收到错误:Traceback(最近一次通话最后一次):
File "/Users/Matthew/Desktop/pygame sheep/interface.py", line 35, in <module>
frame=menu(parent=None,id=-1)
File "/Users/Matthew/Desktop/pygame sheep/interface.py", line 16, in __init__
self.PlayButton=wx.BitmapButton(self.bitmap, -1, PlayButton, pos=())
File "/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/_controls.py", line 192, in __init__
_controls_.BitmapButton_swiginit(self,_controls_.new_BitmapButton(*args, **kwargs))
TypeError: Expected a 2-tuple of integers or a wxPoint object.
我正在运行 Python 2.7.2、wxPython 2.8.12