VOOZH about

URL: https://www.geeksforgeeks.org/python/python-display-text-to-pygame-window/

⇱ Python | Display text to PyGame window - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python | Display text to PyGame window

Last Updated : 9 Apr, 2022

Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of the developer, what type of game he/she wants to develop using this toolkit.
.

Command to install pygame on windows based system :  

pip install pygame


  
There are 7-basic steps to displaying Text on the pygame window : 
 

  • Create a display surface object using display.set_mode() method of pygame.
  • Create a Font object using font.Font() method of pygame.
  • Create a Text surface object i.e.surface object in which Text is drawn on it, using render() method of pygame font object.
  • Create a rectangular object for the text surface object using get_rect() method of pygame text surface object.
  • Set the position of the Rectangular object by setting the value of the center property of pygame rectangular object.
  • Copying the Text surface object to the display surface object using blit() method of pygame display surface object.
  • Show the display surface object on the pygame window using the display.update() method of pygame.


Below is the implementation:
 

Output : 
 

πŸ‘ Output - 1


Now We Will See one of the applications of Displaying the texts but in a different way that is by scrolling the text in 6 different ways on the pygame window.

1. Scrolling the text on top of the Screen.

2. Scrolling the text at the bottom of the screen.

3. Scrolling the text on the left side of the Screen

4. Scrolling the text on the right side of the Screen

5. Scrolling the text in diagonal  from left to right side of the Screen

6. Scrolling the text in diagonal from right side to left side of the Screen.

After Seeing the below Code you can implement your own pattern 

Below is the Implementation

Output:

1. When text is Scrolling on top of Screen

πŸ‘ Image

2. When text is Scrolling on bottom of Screen

πŸ‘ Image

3. When text is Scrolling on left side of Screen

πŸ‘ Image

4. When text is Scrolling on right side of Screen

πŸ‘ Image

5. When text is Scrolling on diagonal from left side of Screen

πŸ‘ Image
πŸ‘ Image

6. When text is Scrolling on diagonal from right side of Screen

πŸ‘ Image

Comment