Python | Display text to PyGame window
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:
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
1. When text is Scrolling on top of Screen
2. When text is Scrolling on bottom of Screen
3. When text is Scrolling on left side of Screen
4. When text is Scrolling on right side of Screen
5. When text is Scrolling on diagonal from left side of Screen
6. When text is Scrolling on diagonal from right side of Screen