2元组wxpython

时间:2012-10-24 01:07:24

标签: python user-interface bitmap wxpython

我一直在制作一个菜单界面,我希望使用背景,然后使用自定义图像作为按钮,但无法显示它们

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()

任何人都可以了解为什么我一直收到错误: 回溯(最近一次调用最后一次):

 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

2 个答案:

答案 0 :(得分:2)

self.PlayButton=wx.BitmapButton(self.bitmap, -1, PlayButton, pos=())
                                                             ^^^^^^

这是无效的 - 你需要给它一个元组,例如(0, 0)或者不指定pos并让它默认。

答案 1 :(得分:0)

self.PlayButton=wx.BitmapButton(self.bitmap, -1, PlayButton, pos=())

这一行是问题所在。该职位必须是元组(x, y)