- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - Display images with PyGame
Pygame is a multimedia library for Python for making games and multimedia applications. In this article we will see how to use the pygame module to paint a picture on the screen taking into consideration, its height, width and position in the pygame window.
In the below program we initialize the pygame module and then define the mode and the caption for the image. Next we load the image and define the coordinates. The screen.blit function paints the screen while the while loop keeps listening the end of the game is clicked.
import pygame pygame.init() w = 300; h = 300 screen = pygame.display.set_mode((w, h)) pygame.display.set_caption('Tutorialspoint Logo') TPImage = pygame.image.load("E:\Python3\tutorialspoint.png").convert() # coordinates of the image x = 10; y = 20; screen.blit(TPImage, (x, y)) # paint screen one time pygame.display.flip() running = True while (running): # loop listening for end of game for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # loop over, quite pygame pygame.quit()
Running the above code gives us the following result −
- Python - Display text to PyGame window
- Python - Drawing different shapes on PyGame window
- Working with Images in Python?
- Python - Working with PNG Images using Matplotlib
- How to work with images in Bokeh (Python)?
- How to display animated gif images in Android?
- Stegosploit: Hacking with Images
- Reading images using Python?
- Resizing images with ImageTk.PhotoImage with Tkinter
- How to display a sequence of images using Matplotlib?
- How to display animated GIF images in Android using Kotlin?
- Blending two images with HTML5 canvas
- How to style images with CSS?
- Add style to images with Bootstrap
- Responsive Images in Bootstrap with Examples