-2

I'm trying to put an image on top of an image after a click of Mouse1 using Pillow v9.1.1. If I run the code, it gives me this error for def button(): (argument 1 must be pygame.Surface, not PngImageFile)

from PIL import Image
import pygame

clock = pygame.time.Clock()

dot = Image.open("dot.png")

buttonImage = Image.open("button.png")
buttonX = 100
buttonY = 350

def dotprint():
    buttonImage.paste(dot, (0, 0))

def button():
    screen.blit(buttonImage, (buttonX, buttonY))


running = True
    while running:

screen.fill((0, 0, 0))

for event in pygame.event.get():
    if event.type == pygame.MOUSEBUTTONDOWN:
        button_press_time1 = pygame.time.get_ticks()
    if event.type == pygame.MOUSEBUTTONUP:
        button_release_time1 = pygame.time.get_ticks()
    if event.type == pygame.QUIT:
        running = False
current_time = pygame.time.get_ticks()
if -17 > button_press_time1 - button_release_time1 > -200:
    dotprint()
    button_release_time1 = 0


button()
pygame.display.update()
clock.tick(60)

How do I change it from PngImageFile to pyagme.Surface?

goose
  • 1
  • 1
  • 1
    Does this answer your question? [Convert PIL Image into pygame surface image](https://stackoverflow.com/questions/38665920/convert-pil-image-into-pygame-surface-image) – gre_gor May 22 '22 at 19:08
  • I just used this guide, just gives me an error of (ValueError: size needs to be (number width, number height).) I just tried to put in the values of print(size) it self, and it still gives me that error. Sorry for being dumb if I am :D – goose May 22 '22 at 19:59

0 Answers0