English 中文(简体)
Pygame - Locals module
  • 时间:2024-12-22

Pygame - Locals Module


Previous Page Next Page  

This module contains definitions of various constants used frequently in a Pygame apppcation. Although, these constants are defined in respective modules, it becomes easier to use them from locals module.

For example, Key or Mouse events (such as KEYDOWN or MOUSEBUTTONDOWN) are defined as pygame.key.KEYDOWN or pygame.mouse.MOUSEBUTTON respectively, these constants can be used without quapfying the module name by importing from locals module.

Here, we are using QUIT event from locals module.


import pygame,sys
from pygame.locals import *
pygame.init()
canvas=pygame.display.set_mode((400,300))
pygame.display.set_caption("Hello")
canvas.fill((0,0,0))
while True:
   for event in pygame.event.get():
      if(event.type == QUIT):
         pygame.quit()
            sys.exit(1)
Advertisements