The installation pit of the pgzrun module in the editing of python primary school students
pip install pgzrun, the installation is wrong, the installation pit , when installing, the correct library name is pgzero
Correct installation: pip install pgzero
The turtle editor automatically installs pygame and this module
Python has a wealth of third-party libraries in various fields. pygame is an application library of python in the game field, which can be used to develop various games. But for beginners, there are still certain thresholds.
pgzero (pygame zero) is a further package based on pygame, which makes it very convenient to design a game, especially suitable for teaching children in the field of programming, and complements scratch.
When I have time, I support my child’s interest in pyzero when he is learning python. At the same time, he slowly integrates the knowledge of python into the development of small games, so that he can learn to develop small games, which can be combined with learning. Unknowingly improve their python level and knowledge level. There is no mistake in playing and learning, mastering knowledge in happiness.
First use this to bring up the game window
import pgzrun
# Global variables and initialization information
TITLE = 'Game First Step'
WIDTH = 400
HEIGHT = 500
# draw game elements
def draw():
pass
# update game state
def update():
pass
# Handle keyboard events
def on_key_down():
pass
# Handle keyboard events
def on_mouse_down():
pass
# implement
pgzrun.go()
building block mode
running result
A black form, followed by the content framed as a whole