简体   繁体   中英

2 tuple wxpython

I've been working on a menu interface where I'm hoping to use a background and then custom images as buttons, however can't get them to display

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

Can anyone shed some light on why I keep getting an error: Traceback (most recent call last):

 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.

I'm running Python 2.7.2, wxPython 2.8.12

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

This isn't valid - you either need to give it a tuple such as (0, 0) or don't specify pos and let it default.

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

This line is the problem. The position needs to be a tuple (x, y)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM