0

I'm creating a card game in pygame and need to display different card graphics dependent on a random roll. I create card_list earlier as a list of jpg files

card_list=[]
for filename in glob.glob('Cards/*.jpg'):
    im = Image.open(filename)
    card_list.append(im)


if cards_button.draw():
            rand  = random.randrange(0,3)       #Just using range of 0-3 to test
            screen.fill((128, 0, 128))
            user_card = card_list[rand]
            screen.blit(user_card, (100,0))`

But I get this error:

Traceback (most recent call last):
  File "C:\Users\Owner\PycharmProjects\TarotGame\main.py", line 102, in <module>
    screen.blit(user_card, (100,0))
TypeError: argument 1 must be pygame.Surface, not JpegImageFile

What am I doing wrong here? Thank you.

I experimented with pygame.image.load() but still no dice.

shafee
  • 15,566
  • 3
  • 19
  • 47

1 Answers1

0

Instead of using Image.open(filename), try using pygame's pygame.image.load(filename) function. My guess is that pygame surfaces are incompatible with files loaded with PIL.

Matt Eng
  • 351
  • 10