-1
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

the main class

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

TypeError: argument 1 must be pygame.Surface, not Button

Can any one help me solve this error?

ᴀʀᴍᴀɴ
  • 4,443
  • 8
  • 37
  • 57
Thaej Sooriya
  • 519
  • 1
  • 4
  • 4
  • `if event.type == pygame.mouse.get_pressed():` this line is incorrect - you compare two different elements. You can compare `event.type == pygame.MOUSEBUTTONDOWN`, and then `if event.button == 1:` and then you can get mouse position `event.pos`. – furas Jan 13 '16 at 01:25

1 Answers1

0

try this:

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

you're currently telling it to blit an object and not the object's sprite

ᴀʀᴍᴀɴ
  • 4,443
  • 8
  • 37
  • 57
oxrock
  • 643
  • 5
  • 12