hello_world.py 706 B

123456789101112131415161718192021222324252627
  1. import pygame, sys
  2. from keyboard import is_pressed
  3. #Initialize pygame and set up window
  4. pygame.init()
  5. winSize = (800, 600)
  6. screen = pygame.display.set_mode(winSize)
  7. pygame.display.set_caption('Display text')
  8. #Load font and render text
  9. myriadProFont = pygame.font.SysFont('Myriad Pro', 48)
  10. helloWorld = myriadProFont.render('Hello World!', 1, (255, 0, 255), (255, 255, 255))
  11. while True:
  12. if is_pressed('q'):
  13. sys.exit()
  14. #Keep screen open and let user exit window using for loop
  15. for ev in pygame.event.get():
  16. if ev.type == pygame.QUIT:
  17. sys.exit()
  18. screen.blit(helloWorld, (0, 0))
  19. #Update window
  20. pygame.display.update()