Typeerror: Argument 1 Must Be Pygame.surface, Not Str [pygame Using Buttons]
Hello I'm creating a game using pygame and I had some problems. I create some buttons (using images)and depending in some actions the Image of this buttons will change.I will show
Solution 1:
The error is self explanatory:
gameDisplay.blit(ip, (x,y))
TypeError: argument 1 must be pygame.Surface, not str
The object ip
should be a pygame.Surface
, instead it is an str
. Perhaps you want to create a dictionary:
button_image_dict = {'default_ip': default_ip,
'default_ap': default_ap,
'chewbacca_ip': chewbacca_ip,
'chewbacca_ap': chewbacca_ap}
And then use this dictionary to find the object from the string:
gameDisplay.blit(button_image_dict[ip], (x,y))
Solution 2:
I have a dictionary of characters: cheracters = {'default':0,'chewbacca':1,'Stormsoldier':2}
First, I think that should be a list. All you're storing is item positions.
If I understand what you're trying to do, you want a dictionary for the images
For example
ap = {
'default' : 'button_menu_ap.png',
'chewbacca' : 'button_select_GalaxyWars_chewbacca_ap.png'
}
nombre = 'chewbacca'
chewbacca_ap = pygame.image.load(ap[nombre])
Post a Comment for "Typeerror: Argument 1 Must Be Pygame.surface, Not Str [pygame Using Buttons]"