在python中创建了一个按钮类,但无法使用pygame添加到屏幕上

时间:2016-01-12 22:23:45

标签: python pygame pygame-surface

import pygame, sys, time, random

from pygame.locals import*

pygame.init()

class Button(object):

def __init__(self, x, y):
    '''x_size, y_size,'''
    #self.name = name
    '''self.length = x_size'''
    '''self.height = y_size'''
    self.xpos = x
    self.ypos = y
    self.rect = (100,100)
    self.image = ('Images\Button_Test.png')

def getRect(self):
    return self.rect


def onClick():
    for event in pygame.event.get():
        if event.type == pygame.mouse.get_pressed():
            pos = pygame.mouse.get_pos()
            if self.collidepoint(pos):
                return

主要班级

screen.blit(background,(0,0))
screen.blit(testButton, testButton.getRect())
pygame.display.flip()
  

TypeError:参数1必须是pygame.Surface,而不是Button

任何人都可以帮我解决这个错误吗?

1 个答案:

答案 0 :(得分:0)

试试这个:

screen.blit(testbutton.image,testbutton.get_rect())

你现在告诉blit一个对象,而不是对象的精灵