Pygame Tutorial
Selected Reading
- Pygame - Discussion
- Pygame - Useful Resources
- Pygame - Quick Guide
- Pygame - Errors and Exception
- Pygame - PyOpenGL
- Pygame - The Sprite Module
- Pygame - Access CDROM
- Pygame - Load cursor
- Pygame - Using Camera module
- Pygame - Playing Movie
- Pygame - Playing music
- Pygame - Mixer channels
- Pygame - Sound objects
- Pygame - Transforming Images
- Pygame - Use Text as Buttons
- Pygame - Moving Rectangular objects
- Pygame - Moving with mouse
- Pygame - Moving with Numeric pad keys
- Pygame - Moving an image
- Pygame - Displaying Text in Window
- Pygame - Loading image
- Pygame - Drawing shapes
- Pygame - Mouse events
- Pygame - Keyboard events
- Pygame - Event objects
- Pygame - Color object
- Pygame - Locals module
- Pygame - Display modes
- Pygame - Hello World
- Pygame - Overview
- Pygame - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Pygame - Locals module
Pygame - Locals Module
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