Python error ValueError size needs to be int width int height while using pygame Surface

0 votes

I'm trying to build a game on python using pygame. I am stuck with this error:

self._image_surf = pygame.Surface("pygame.png").convert()
ValueError: size needs to be (int width, int height)

Can you help me out?

Lines causing error:

pygame.display.set_caption('Pygame pythonspot.com example')
self._running = True
self._image_surf = pygame.Surface("pygame.png").convert()
Jun 19, 2019 in Python by Jinu
1,226 views

1 answer to this question.

0 votes

pygame.Surface takes in integer values for building the image. You're giving an image as the parameter which is syntactically wrong.

Try:

pygame.Surface(100, 100)

This should work.

answered Jun 19, 2019 by Varsha

Related Questions In Python

+1 vote
10 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

Just for the record: >>> int('55063.000000') Traceback (most recent ...READ MORE

answered Aug 17, 2020 in Python by pakainfo
• 200 points
227,032 views
0 votes
1 answer

Pyplot error "only size-1 arrays can be converted to Python scalars"

You can plot the chart by taking ...READ MORE

answered Jan 28, 2019 in Python by Omkar
• 69,090 points
8,329 views
0 votes
0 answers

Python error "only size-1 arrays can be converted to Python scalars"

I'm trying to plot the exponential and ...READ MORE

Jul 9, 2019 in Python by JTM
951 views
0 votes
0 answers

Pyplot error "only size-1 arrays can be converted to Python scalars"

I am getting the following error while ...READ MORE

Nov 28, 2019 in Python by Sumit
• 130 points
2,584 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,830 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,413 views
0 votes
2 answers

How can I write a program to add two numbers using functions in python?

there is sum() function as a built ...READ MORE

answered Oct 24, 2020 in Python by anonymous
12,700 views
0 votes
1 answer

Python pygame error : Failed loading libpng.dylib: dlopen(libpng.dylib, 2): image not found

Try installing libpng You can do it with ...READ MORE

answered May 31, 2019 in Python by SDeb
• 13,250 points
713 views