Pygame – Locals module


Pygame – Locals Module



”;


This module contains definitions of various constants used frequently in a Pygame application. 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 qualifying 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

”;

Leave a Reply

Your email address will not be published. Required fields are marked *