Skip to content
Sign upLog in
← Back to Community
How to insert image in python pygame i cant drag a file
Profile icon
Phantom0627

i use ubuntu to code pls help me how How to insert image in python pygame i cant drag a file i am a student pls hellp

Voters
Profile icon
Phantom0627
Comments
hotnewtop
Profile icon
maxina

First, just upload the file/image to your folder in your repl. Next, to insert an image in pygame, here is sample code:

import pygame
pygame.init()

white = (255, 255, 255)

X = 400
Y = 400

display_surface = pygame.display.set_mode((X, Y ))

set the pygame window name

pygame.display.set_caption('Image')

#load image
image = pygame.image.load(r'C:\Users\user\Pictures\test.jpg')

while True :

display_surface.fill(white) #pu the image to the screen display_surface.blit(image, (0, 0)) for event in pygame.event.get() : if event.type == pygame.QUIT : pygame.quit() quit() pygame.display.update()
Profile icon
supcoolak

Well, I don't know what you want the image for, but

@TommyVictory
below did say how to upload. To use the image in pygame, use pygame.image.load('path/to/image').

Profile icon
mesquite2234

Press the three dots

image

Then press upload file