Created
June 1, 2020 15:19
-
-
Save arpit-omprakash/3dc2d202e8711962bb2153c135516fb8 to your computer and use it in GitHub Desktop.
A simple Hello World program in Pygame to introduce users to fonts and text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame, sys | |
from pygame.locals import * | |
pygame.init() | |
DISPLAYSURF = pygame.display.set_mode((400,300)) | |
pygame.display.set_caption('Hello World') | |
WHITE = (255, 255, 255) | |
GREEN = (0, 255, 0) | |
BLUE = (0, 0, 128) | |
fontObj = pygame.font.Font('freesansbold.ttf', 32) | |
textSurfaceObj = fontObj.render('Hello World!', True, GREEN, BLUE) | |
textRectObj = textSurfaceObj.get_rect() | |
textRectObj.center = (200,150) | |
while True: | |
DISPLAYSURF.fill(WHITE) | |
DISPLAYSURF.blit(textSurfaceObj, textRectObj) | |
for event in pygame.event.get(): | |
if event.type == QUIT: | |
pygame.quit() | |
sys.exit() | |
pygame.display.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment