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
5,738 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

+2 votes
10 answers

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

The following are totally acceptable in python: passing ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,560 points
409,222 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,220 points
9,472 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
1,793 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
3,736 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 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,790 points
4,071 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 25, 2020 in Python by anonymous
23,843 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,300 points
1,722 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP