pygame python

# Be sure to install pygame via pip

import pygame
import sys

# initialize it
pygame.init()

# configurations
frames_per_second = 30
window_height = 600
window_width = 400

# colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BLUE = (0, 0, 255)

# creating window
display = pygame.display.set_mode((window_width, window_height))

# creating our frame regulator
clock = pygame.time.Clock()

# forever loop
while True:
  # frame clock ticking
  clock.tick(frames_per_second)
  
  # frame Drawing
  display.fill(WHITE)
  
  # event loop
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      pygame.quit()
      sys.exit()
      

4
9
Potherca 95 points

                                    pip install pygame

And import the library.

import pygame

4 (9 Votes)
0
4
1

                                    Pygame is a good choice for creating GUI and game dev.
Install:
Windows:
pip install pygame

4 (1 Votes)
0
5
5

                                     1# Simple pygame program
 2
 3# Import and initialize the pygame library
 4import pygame
 5pygame.init()
 6
 7# Set up the drawing window
 8screen = pygame.display.set_mode([500, 500])
 9
10# Run until the user asks to quit
11running = True
12while running:
13
14    # Did the user click the window close button?
15    for event in pygame.event.get():
16        if event.type == pygame.QUIT:
17            running = False
18
19    # Fill the background with white
20    screen.fill((255, 255, 255))
21
22    # Draw a solid blue circle in the center
23    pygame.draw.circle(screen, (0, 0, 255), (250, 250), 75)
24
25    # Flip the display
26    pygame.display.flip()
27
28# Done! Time to quit.
29pygame.quit()

5 (5 Votes)
0
3.78
9
Bri-bri 105 points

                                    # Pygame boiler plate
# Should have a red square on screen if run
# pip3 install pygame

import pygame

screen = pygame.display.set_mode((1280, 720))

running = True
while running:
	screen.fill((0, 0, 0))
  
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			running = False

	pygame.draw.rect(screen, (255, 0, 0), ((10, 10), (50, 50)))
            
	pygame.display.update()
    
pygame.quit()
	

3.78 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
pygame pytho py pygame does pygame come with python3 matplotlib pygame pygame python3 pygame package in python how to use pygame module in python pycairo pygame pygame é python and pygame what is a pygame brython pygame pygame pyhton what does pygame does pygame python module Game in python pygame pygame import pygame pygame in python code pygame module code code in pygame programming with pyhton and pygame does pygame come with python python lib pygame pygame library in python module pygame python 3 python import pygame python pygame code import pygame in python pygame python documentation pygame pygame python pygame documentation pygame.org pygame. pygame pythpon python pygame pypi pygame \ what is python pygame pygame syntax pygame games pygame physics python pygame module pygame ipython pypy with pygame pygame python games pygame module in pythoon pythonista pygame python e pygame pygame p pythongame code pygame python do pygame with pygame python pygame pygame org 'pygame' python programming pygame pygame module pygame game how to use pygame in python python pygame library python pygame game code pygame.U pygame module in python pygame pythonprogramming.net pygame pypy pygame 3 pygame designing a game engine is pygame a good way to learn python best pygame tutorial OOP with pygame pygame simulator how to create an object in pygame free download pygameing laberiea python pygame labyrinthe pygame development pygame how to use pygame documentation pygame game manager class pygame basics online pygame compiler with sprites pygame tutorials game pygame tutorial pythoinprogramming.net pygame code how to set up a simple python pygame script pygame library pypi pygame among us but with pygame This is pygame pygame documaentation pygame create game pygame how to pygame uses quick pygame tutorial pygame programming language echec python pygame what will screen.blit(surf, (400, 300)) output> what is pygame all code pygame python game development with pygame pygame intro and basics python pge pygame pygame pypy pygame pygame python python 3 pygame pygame python 3 learn pygame a* pygame pygame 2 notes pygame walkthrough what is pygame in python intro to pygame how to use python pygame anong us pygame python pygame tutorial is it PyGame or pygame pygame in python basic pygame pygame for 3 pyhon pygame pygame first how to use pygame using pygame what is micropython pygame pygame and python how to pygame pygame tutorial 1 pygame tutorial python 3 what does it mean when a company sends a pygames pygame tutorial 17 pygame tutorial pygame pygame python programming python pygames pygame tutorial for beginners python pygame using pygame in python
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source