Skip to content

Instantly share code, notes, and snippets.

@arpit-omprakash
Created June 1, 2020 15:19
Show Gist options
  • Save arpit-omprakash/3dc2d202e8711962bb2153c135516fb8 to your computer and use it in GitHub Desktop.
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
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