Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • GfG 160: Daily DSA
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Turtle
  • Tkinter
  • Matplotlib
  • Python Imaging Library
  • Pyglet
  • Python
  • Numpy
  • Pandas
  • Python Database
  • Data Science With Python
  • Machine Learning with Python
  • Django
  • Flask
  • R
Open In App
Next Article:
Introduction to pygame
Next article icon

PyGame Tutorial

Last Updated : 08 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Pygame is a free and open-source library for making games and multimedia applications in Python. It helps us create 2D games by giving us tools to handle graphics, sounds and user input (like keyboard and mouse events) without needing to dig deep into complex stuff like graphics engines.

  • Release date: 28 October 2000
  • Programming languages: Python, C, Cython, Assembly language
  • Developer: Pete Shinners
  • License: GNU Lesser General Public License
  • Stable release: 2.5.0 / 24 June 2023; 6 months ago

What we can do with Pygame:

  1. Draw shapes, images and text on the screen
  2. Play music and sound effects
  3. Detect keyboard, mouse or joystick input
  4. Control the frame rate of your game
  5. Build simple 2D games like platformers, puzzles or shooters

Interesting Facts about PyGame

  • Pygame is Over Two Decades Old: Pygame was first released in the year 2000! It’s been helping people make games with Python for over 20 years.
  • Built on Top of SDL: Pygame is a wrapper for SDL (Simple DirectMedia Layer), which is a powerful low-level multimedia library used in many commercial games.
  • No Game Engine Needed: Unlike Unity or Unreal, Pygame is more low-level — it gives you the tools to build everything from scratch, helping you learn core game development logic.
  • Tiny File Size: Despite its power, Pygame is lightweight and doesn’t require huge installations or tools.
  • Pygame Zero is a Simplified Version: There’s a simpler version called Pygame Zero, which is made for kids and beginners to start coding games with almost zero setup.

Code Example of Pygame:

  • This code creates a basic Pygame window with the title "Hello Pygame".
  • It runs a loop that keeps the window open and listens for events like closing the window.
  • When the close button is clicked, the loop stops, and the game exits cleanly.
  • It's the typical starting point for any Pygame project to get a working window on screen.
Python
import pygame

# Initialize Pygame
pygame.init()

# Set up the game window
screen = pygame.display.set_mode((400, 300))
pygame.display.set_caption("Hello Pygame")

# Game loop
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

# Quit Pygame
pygame.quit()

Output

PyGame
PyGame

PyGame Tutorial

To get the latest stable version of pygame, you can download it from this link.

Introduction

In this section, we’ll start with the basics of Pygame. You’ll get an idea of what Pygame is, how it works and why it’s popular for creating 2D games with Python. We’ll walk through how to set it up on both Windows and MacOS and even include a few interesting facts that’ll give you a better feel for the Pygame world.

  • Introduction to pygame
  • Getting Started with Pygame
  • How to install Pygame in Windows?
  • Install Pygame on MacOS
  • Interesting Facts about PYGAME

Getting Started

In this part, we’ll learn how to import and initialize Pygame, create a game window, customize things like the window name, background color and icon and understand how the game loop works. We’ll also touch on key concepts like surfaces and handling time in Pygame and all the building blocks needed before you start adding game elements.

  • PyGame – Import and Initialize
  • How to initialize all the imported modules in PyGame?
  • How to create an empty PyGame window?
  • How to get the size of the PyGame Window?
  • Allowing resizing window in PyGame
  • How to change screen background color in Pygame?
  • How to Change the Name of a Pygame window?
  • How to set up the Game Loop in PygGame?
  • How to change the PyGame icon?
  • Pygame - Surfaces
  • Pygame - Time

Drawing Shapes

In this section, we’ll explore how to draw basic shapes using Pygame. You’ll learn how to create rectangles (including ones with rounded corners) and how to use Pygame’s drawing tools to place different shapes and objects onto the game window. These are the visual elements that help bring your game to life.

  • Pygame - Drawing Objects and shapes
  • Python | Drawing different shapes on PyGame window
  • How to draw a rectangle in Pygame?
  • How to draw a rectangle with rounded corners in PyGame?

Event Handling

In this part, we’ll look at how your game can react to player actions. You’ll learn how event handling works in Pygame and from detecting key presses to creating custom events. We’ll also cover how to handle user input and even play audio files, making your game feel more interactive and dynamic.

  • Pygame - Event Handling
  • How to add Custom Events in Pygame?
  • Pygame - Input Handling
  • How to get keyboard input in pygame?
  • Python | Playing audio file in Pygame

Working with Text

In this section, you’ll learn how to work with text in Pygame. We’ll cover how to display text on the screen, customize its appearance and even create a text input box so users can type into your game. This is useful for things like scores, messages or entering player names.

  • Pygame – Working with Text
  • Python | Display text to PyGame window
  • How to create a text input box with Pygame?

Working with images

In this section, you’ll learn how to load and display images in Pygame. We’ll cover how to get image dimensions, rotate, scale and flip images and even let users interact with images using the mouse. These skills will help you add characters, backgrounds and interactive visuals to your game.

  • Python | Display images with PyGame
  • Getting the width and height of an image in Pygame
  • How to Rotate and Scale images using PyGame?
  • Pygame - Flip the image
  • How to move an image with the mouse in PyGame?
  • How to use the mouse to scale and rotate an image in PyGame?

PyGame Advance

You’ll learn how to create buttons, move objects with keyboard input, make them jump, add boundaries and handle collisions. We’ll also cover working with sprites, how to create them, control them and add cool visual effects like color breezing. These topics will help take your game from basic to polished and interactive.

  • How to Create Buttons in a game using PyGame?
  • Python – Drawing design using arrow keys in PyGame
  • Python – Moving an object in PyGame
  • Python | Making an object jump in PyGame
  • Adding Boundary to an Object in Pygame
  • Collision Detection in PyGame
  • Pygame - Creating Sprites
  • Pygame - Control Sprites
  • How to add color breezing effect using pygame?
  • Playing audio files in Pygame

Exercise, Applications and Projects

In this section, you’ll put everything you’ve learned into practice through fun exercises, creative visualizations and full projects. From classic games like Snake and Tic Tac Toe to cool effects like snowfall and color breezing, you’ll build real applications using Pygame. You’ll also explore how to visualize algorithms like sorting and searching and even create a Sudoku game. This is where your coding skills turn into playable, visual experiences!

  • How to add color breezing effect using pygame?
  • Snowfall display using Pygame in Python
  • Rhodonea Curves and Maurer Rose in Python
  • Creating start Menu in Pygame
  • Tic Tac Toe GUI In Python using PyGame
  • Snake Game
  • 8-bit game using pygame
  • Bubble sort visualizer using PyGame
  • Ternary Search Visualization using Pygame in Python
  • Sorting algorithm visualization: Heap Sort
  • Sorting algorithm visualization: Insertion Sort
  • Binary Search Visualization using Pygame in Python
  • Building and visualizing Sudoku Game Using Pygame

Next Article
Introduction to pygame

N

nikhilaggarwal3
Improve
Article Tags :
  • Python
  • Python-PyGame
  • Tutorials
Practice Tags :
  • python

Similar Reads

    PyGame Tutorial
    Pygame is a free and open-source library for making games and multimedia applications in Python. It helps us create 2D games by giving us tools to handle graphics, sounds and user input (like keyboard and mouse events) without needing to dig deep into complex stuff like graphics engines.Release date
    7 min read

    Introduction

    Introduction to pygame
    Pygame is a set of Python modules designed for writing video games. It adds functionality on top of the excellent SDL library, enabling you to create fully-featured games and multimedia programs in the Python language. It's key benefits include:Beginner-Friendly: Simple Python syntax makes it ideal
    4 min read
    Getting Started with Pygame
    Pygame is a free-to-use and open-source set of Python Modules.  And as the name suggests, it can be used to build games. You can code the games and then use specific commands to change it into an executable file that you can share with your friends to show them the work you have been doing.  It incl
    3 min read
    How to Install Pygame on Windows ?
    In this article, we will learn how to Install PyGame module of Python on Windows. PyGame is a library of python language. It is used to develop 2-D games and is a platform where you can set python modules to develop a game. It is a user-friendly platform that helps to build games quickly and easily.
    2 min read
    Install Pygame in MacOS
    PyGame is a collection of modules that break through the language of Python applications. These modules are designed to edit video games. PyGame, therefore, includes computer graphics and audio libraries created for the use and language of Python programs. At first, open the Terminal which is locate
    1 min read
    Interesting Facts about PYGAME
    Pygame is a set of python module which is used in designing video games. In Pygame, there are computer graphics and sound libraries in order to develop high quality and user interactive games. Pygame was developed by Pete Shinners. Till 2000, it was a community project, later on it was released unde
    2 min read

    Getting Started

    PyGame - Import and Initialize
    In this article, we will see how to import and initialize PyGame. Installation The best way to install pygame is with the pip tool, we can install pygame by using the below command: pip install pygameImporting the Pygame library To import the pygame library, make sure you have installed pygame alrea
    2 min read
    How to initialize all the imported modules in PyGame?
    PyGame is Python library designed for game development. PyGame is built on the top of SDL library so it provides full functionality to develop game in Python. Pygame has many modules to perform it's operation, before these modules can be used, they must be initialized. All the modules can be initial
    2 min read
    How to create an empty PyGame window?
    Pygame window is a simple window like any other window, in which we display our game screen. It is the first task we do so that we can display our output onto something. Our main goal here is to create a window and keep it running unless the user wants to quit. To perform these tasks first we need t
    2 min read
    How to get the size of PyGame Window?
    In this article, we will learn How to get the size of a PyGame Window.  Game programming is very rewarding nowadays and it can also be used in advertising and as a teaching tool too. Game development includes mathematics, logic, physics, AI, and much more and it can be amazingly fun. In python, game
    1 min read
    Allowing resizing window in PyGame
    In this article, we will learn How to allow resizing a PyGame Window.  Game programming is very rewarding nowadays and it can also be used in advertising and as a teaching tool too. Game development includes mathematics, logic, physics, AI, and much more and it can be amazingly fun. In python, game
    2 min read
    How to change screen background color in Pygame?
    Pygame is a Python library designed to develop video games. Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language. Functions Used: pygame.init(): This function is used to initialize all the pygame
    1 min read
    How to Change the Name of a Pygame window?
    PyGame window is a simple window that displays our game on the window screen. By default, pygame uses "Pygame window" as its title and pygame icon as its logo for pygame window. We can use set_caption() function to change the name and set_icon() to set icon of our window. To change the name of pygam
    2 min read
    How to set up the Game Loop in PygGame ?
    In this article, we will see how to set up a game loop in PyGame. Game Loop is the loop that keeps the game running. It keeps running till the user wants to exit. While the game loop is running it mainly does the following tasks: Update our game window to show visual changesUpdate our game states ba
    3 min read
    How to change the PyGame icon?
    While building a video game, do you wish to set your image or company's logo as the icon for a game? If yes, then you can do it easily by using set_icon() function after declaring the image you wish to set as an icon. Read the article given below to know more in detail.  Syntax: pygame_icon = pygame
    2 min read
    Pygame - Surface
    When using Pygame, surfaces are generally used to represent the appearance of the object and its position on the screen. All the objects, text, images that we create in Pygame are created using surfaces. Creating a surface Creating surfaces in pygame is quite easy. We just have to pass the height an
    6 min read
    Pygame - Time
    While using pygame we sometimes need to perform certain operations that include the usage of time. Like finding how much time our program has been running, pausing the program for an amount of time, etc. For operations of this kind, we need to use the time methods of pygame. In this article, we will
    4 min read

    Drawing Shapes

    Pygame – Drawing Objects and Shapes
    In this article, we are going to see how to draw an object using Pygame. There can be two versions for drawing any shape, it can be a solid one or just an outline of it. Drawing Objects and Shapes in PyGame You can easily draw basic shapes in pygame using the draw method of pygame.  Drawing Rectangl
    10 min read
    Python | Drawing different shapes on PyGame window
    Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of developer, what type of game he/she wants to develop using th
    3 min read
    How to draw rectangle in Pygame?
    Pygame is a Python library designed to develop video games. Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language. Functions  Used: pygame.display.set_mode(): This function is used to initialize a
    1 min read
    How to draw a rectangle with rounded corner in PyGame?
    Pygame is a Python library designed to develop video games. Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language. In this article, we will see how can we draw a rectangle with rounded corners in P
    2 min read

    Event Handling

    How to add Custom Events in Pygame?
    In this article, we will see how to add custom events in PyGame.  Installation PyGame library can be installed using the below command: pip install pygame Although PyGame comes with a set of events (Eg: KEYDOWN and KEYUP), it allows us to create our own additional custom events according to the requ
    4 min read
    How to get keyboard input in PyGame ?
    While using pygame module of Python, we sometimes need to use the keyboard input for various operations such as moving a character in a certain direction. To achieve this, we have to see all the events happening. Pygame keeps track of events that occur, which we can see with the events.get() functio
    3 min read

    Working with Text

    Pygame - Working with Text
    In this article, we will see how to play with texts using the Pygame module. We will be dealing here with initializing the font, rendering the text, editing the text using the keyboard, and adding a blinking cursor note.  Installation To install this module type the below command in the terminal. pi
    5 min read
    Python | Display text to PyGame window
    Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of the developer, what type of game he/she wants to develop usin
    6 min read
    How to create a text input box with Pygame?
    In this article, we will discuss how to create a text input box using PyGame. Installation Before initializing pygame library we need to install it. This library can be installed into the system by using pip tool that is provided by Python for its library installation. Pygame can be installed by wri
    3 min read

    Working with images

    Python | Display images with PyGame
    Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of the developer, what type of game he/she wants to develop usin
    2 min read
    Getting width and height of an image in Pygame
    Prerequisites: Pygame To use graphics in python programs we use a module called Pygame. Pygame provides high functionality for developing games and graphics in Python. Nowadays Pygame are very much popular to build simple 2D games. In order to run a program written in Python using Pygame module, a s
    3 min read
    How to Rotate and Scale images using PyGame ?
    In this article, we are going to see how to Rotate and Scale the image. Image Scaling refers to the resizing of the original image and Image Rotation refers to turning off an image with some angle. Rotations in the coordinate plane are counterclockwise. Let's proceed with the methods used and the co
    3 min read
    Pygame - Flip the image
    In this article, we are going to see how images can be flipped using Pygame. To flip the image we need to use pygame.transform.flip(Surface, xbool, ybool) method which is called to flip the image in vertical direction or horizontal direction according to our needs. Syntax: pygame.transform.flip(Surf
    2 min read
    How to move an image with the mouse in PyGame?
    Pygame is a Python library that is used to create cross-platform video games. The games created by Pygame can be easily run through any of the input devices such as a mouse, keyboard, and joystick. Do you want to make a game that runs through mouse controls? Don't you know how to move the image with
    4 min read
    How to use the mouse to scale and rotate an image in PyGame ?
    In this article, we will discuss how to transform the image i.e (scaling and rotating images) using the mouse in Pygame. Approach Step 1: First, import the libraries Pygame and math. import pygame import math from pygame.locals import * Step 2: Now, take the colors as input that we want to use in th
    5 min read

    PyGame Advance

    How to create Buttons in a game using PyGame?
    Pygame is a Python library that can be used specifically to design and build games. Pygame only supports 2D games that are build using different shapes/images called sprites. Pygame is not particularly best for designing games as it is very complex to use and lacks a proper GUI like unity gaming eng
    3 min read
    Python - Drawing design using arrow keys in PyGame
    Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of developer, what type of game he/she wants to develop using th
    3 min read
    Moving an object in PyGame - Python
    To make a game or animation in Python using PyGame, moving an object on the screen is one of the first things to learn. We will see how to move an object such that it moves horizontally when pressing the right arrow key or left arrow key on the keyboard and it moves vertically when pressing up arrow
    2 min read
    Python | Making an object jump in PyGame
    Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of developer, what type of game he/she wants to develop using th
    3 min read
    Adding Boundary to an Object in Pygame
    Boundaries to any game are very important. In snake games, space invaders, ping pong game, etc. the boundary condition is very important. The ball bounces at the boundaries of the screen in ping pong games. So, the idea behind this boundaries is to change the position of the ball or object in revers
    5 min read
    Collision Detection in PyGame
    Prerequisite: Introduction to pygame Collision detection is a very often concept and used in almost games such as ping pong games, space invaders, etc. The simple and straight forward concept is to match up the coordinates of the two objects and set a condition for the happening of collision. In thi
    7 min read
    Pygame - Creating Sprites
    Sprites are objects, with different properties like height, width, color, etc., and methods like moving right, left, up and down, jump, etc. In this article, we are looking to create an object in which users can control that object and move it forward, backward, up, and down using arrow keys. Let fi
    2 min read
    Pygame - Control Sprites
    In this article, we will discuss how to control the sprite, like moving forward, backward, slow, or accelerate, and some of the properties that sprite should have. We will be adding event handlers to our program to respond to keystroke events, when the player uses the arrow keys on the keyboard we w
    4 min read
    How to add color breezing effect using pygame?
    Pygame is a python library that can be used specifically to design and build games. Pygame supports only 2d games that are built using different sprites. Pygame is not particularly best for designing games as it is very complex to use and doesn’t have a proper GUI like unity but it definitely builds
    2 min read
    Python | Playing audio file in Pygame
    Game programming is very rewarding nowadays and it can also be used in advertising and as a teaching tool too. Game development includes mathematics, logic, physics, AI and much more and it can be amazingly fun. In python, game programming is done in pygame and it is one of the best modules for doin
    2 min read

    Exercise, Applications, and Projects

    Snowfall display using Pygame in Python
    Not everybody must have witnessed Snowfall personally but wait a minute, What if you can see the snowfall right on your screen by just a few lines of creativity and Programming.  Before starting the topic, it is highly recommended revising the basics of Pygame.  Steps for snowfall creation 1. Import
    3 min read
    Rhodonea Curves and Maurer Rose in Python
    In this article, we will create a Rhodonea Curve and Maurer Rose pattern in Python! Before we proceed to look at what exactly is a rhodonea curve or maurer rose we need to get the basic structure of our program ready!  Basic Structure of the Program - Before we move on to learn anything about Rhodon
    7 min read
    Creating start Menu in Pygame
    Pygame is a Python library that can be used specifically to design and build games. Pygame supports only 2d games that are built using different shapes or sprites. Pygame doesn't have an in-built layout design or any in-built UI system this means there is no easy way to make UI or levels for a game.
    3 min read
    Tic Tac Toe GUI In Python using PyGame
    This article will guide you and give you a basic idea of designing a game Tic Tac Toe using pygame library of Python. Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming l
    15+ min read
    Snake Game in Python - Using Pygame module
    Snake game is one of the most popular arcade games of all time. In this game, the main objective of the player is to catch the maximum number of fruits without hitting the wall or itself. Creating a snake game can be taken as a challenge while learning Python or Pygame. It is one of the best beginne
    15+ min read
    8-bit game using pygame
    Pygame is a python library that can be used specifically to design and build games. Pygame supports only 2d games that are built using different sprites. Pygame is not particularly best for designing games as it is very complex to use doesn’t have a proper GUI like unity but it definitely builds log
    9 min read
    Bubble sort visualizer using PyGame
    In this article we will see how we can visualize the bubble sort algorithm using PyGame i.e when the pygame application get started we can see the unsorted bars with different heights and when we click space bar key it started getting arranging in bubble sort manner i.e after every iteration maximum
    3 min read
    Ternary Search Visualization using Pygame in Python
    An algorithm like Ternary Search can be understood easily by visualizing. In this article, a program that visualizes the Ternary Search Algorithm has been implemented. The Graphical User Interface(GUI) is implemented in Python using pygame library. Approach Generate random array, sort it using any s
    5 min read
    Sorting algorithm visualization : Heap Sort
    An algorithm like Heap sort can be understood easily by visualizing. In this article, a program that visualizes the Heap Sort Algorithm has been implemented. The Graphical User Interface(GUI) is implemented in Python using pygame library. Approach: Generate random array and fill the pygame window wi
    4 min read
    Sorting algorithm visualization : Insertion Sort
    An algorithm like Insertion Sort can be understood easily by visualizing. In this article, a program that visualizes the Insertion Sort Algorithm has been implemented. The Graphical User Interface(GUI) is implemented in python using pygame library. Approach: Generate random array and fill the pygame
    3 min read
    Binary Search Visualization using Pygame in Python
    An algorithm like Binary Search can be understood easily by visualizing. In this article, a program that visualizes the Binary Search Algorithm has been implemented. The Graphical User Interface(GUI) is implemented in Python using pygame library. Approach Generate random array, sort it using any sor
    4 min read
    Building and visualizing Sudoku Game Using Pygame
    Sudoku is a logic-based, combinatorial number-placement puzzle. The objective is to fill a 9×9 grid with digits so that each column, each row, and each of the nine 3×3 subgrids that compose the grid contain all of the digits from 1 to 9.  We will be building the Sudoku Game in python using pygame li
    7 min read
    Create Bingo Game Using Python
    A card with a grid of numbers on it is used to play the popular dice game of bingo. Players check off numbers on their cards when they are selected at random by a caller, competing to be the first to mark off all of their numbers in a particular order. We'll examine how to utilise Python to create a
    9 min read
    Create Settings Menu in Python - Pygame
    Python is a flexible programming language with a large selection of libraries and modules for a variety of applications. Pygame menu is one such toolkit that enables programmers to design graphical user interfaces for games and apps. In this tutorial, we'll look at how to use the pygame menu package
    9 min read
    Car Race Game In PyGame
    In this article, we will see how to create a racing car game in Python using Pygame. In this game, we will have functionality like driving, obstacle crashing, speed increment when levels are passed, pause, countdown, scoreboard, and Instruction manual screen.  Required Modules: Before going any furt
    15+ min read
    Spiral Sprint Game in Python Using Pygame
    In this article, we will see how to create a spiral sprint game in Python using Pygame. In this game, we will have functionality like difficulty modes, obstacle crashing, speed increment when points are increased, scoreboard, Particle animation, color-changing orbits, coins, and game sounds. Spiral
    15+ min read
    Selection sort visualizer using PyGame
    In this article, we will see how to visualize Selection sort using a Python library PyGame. It is easy for the human brain to understand algorithms with the help of visualization. Selection sort is a simple and easy-to-understand algorithm that is used to sort elements of an array by dividing the ar
    3 min read
    Mouse Clicks on Sprites in PyGame
    The interactiveness of your game can be significantly increased by using Pygame to respond to mouse clicks on sprites. You may develop unique sprite classes that manage mouse events and react to mouse clicks with the aid of Pygame's sprite module. This article will teach you how to use Pygame to mak
    3 min read
    Slide Puzzle using PyGame - Python
    Slide Puzzle game is a 2-dimensional game i.e the pieces can only be removed inside the grid and reconfigured by sliding them into an empty spot. The slide puzzle game developed here is a 3X3 grid game i.e 9 cells will be there from 1 to 8(9 is not here since a blank cell is needed for sliding the n
    14 min read
    Brick Breaker Game In Python using Pygame
    Brick Breaker is a 2D arcade video game developed in the 1990s. The game consists of a paddle/striker located at the bottom end of the screen, a ball, and many blocks above the striker. The basic theme of this game is to break the blocks with the ball using the striker. The score is calculated by th
    14 min read
    Hover Button in Pygame
    Here, we will talk about while hovering over the button different actions will perform like background color, text size, font color, etc. will change. In this article we are going to create a button using the sprites Pygame module of Python then, when hovering over that button we will perform an eve
    6 min read
    Create a Pong Game in Python - Pygame
    Pong is a table tennis-themed 2-player 2D arcade video game developed in the early 1970s. The game consists of two paddles/strikers, located at the left and right edges of the screen, and a ball. Create a Pong Game in PythonThe basic theme of this game is to make sure that the ball doesn't hit the w
    10 min read
    Save/load game Function in Pygame
    Pygame is a free-to-use and open-source set of Python Modules.  And as the name suggests, it can be used to build games, and to save game data or the last position of the player you need to store the position of the player in a file so when a user resumes the game its game resumes when he left. In t
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

'); // $('.spinner-loading-overlay').show(); let script = document.createElement('script'); script.src = 'https://assets.geeksforgeeks.org/v2/editor-prod/static/js/bundle.min.js'; script.defer = true document.head.appendChild(script); script.onload = function() { suggestionModalEditor() //to add editor in suggestion modal if(loginData && loginData.premiumConsent){ personalNoteEditor() //to load editor in personal note } } script.onerror = function() { if($('.editorError').length){ $('.editorError').remove(); } var messageDiv = $('
').text('Editor not loaded due to some issues'); $('#suggestion-section-textarea').append(messageDiv); $('.suggest-bottom-btn').hide(); $('.suggestion-section').hide(); editorLoaded = false; } }); //suggestion modal editor function suggestionModalEditor(){ // editor params const params = { data: undefined, plugins: ["BOLD", "ITALIC", "UNDERLINE", "PREBLOCK"], } // loading editor try { suggestEditorInstance = new GFGEditorWrapper("suggestion-section-textarea", params, { appNode: true }) suggestEditorInstance._createEditor("") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } //personal note editor function personalNoteEditor(){ // editor params const params = { data: undefined, plugins: ["UNDO", "REDO", "BOLD", "ITALIC", "NUMBERED_LIST", "BULLET_LIST", "TEXTALIGNMENTDROPDOWN"], placeholderText: "Description to be......", } // loading editor try { let notesEditorInstance = new GFGEditorWrapper("pn-editor", params, { appNode: true }) notesEditorInstance._createEditor(loginData&&loginData.user_personal_note?loginData.user_personal_note:"") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } var lockedCasesHtml = `You can suggest the changes for now and it will be under 'My Suggestions' Tab on Write.

You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!`; var badgesRequiredHtml = `It seems that you do not meet the eligibility criteria to create improvements for this article, as only users who have earned specific badges are permitted to do so.

However, you can still create improvements through the Pick for Improvement section.`; jQuery('.improve-header-sec-child').on('click', function(){ jQuery('.improve-modal--overlay').hide(); $('.improve-modal--suggestion').hide(); jQuery('#suggestion-modal-alert').hide(); }); $('.suggest-change_wrapper, .locked-status--impove-modal .improve-bottom-btn').on('click',function(){ // when suggest changes option is clicked $('.ContentEditable__root').text(""); $('.suggest-bottom-btn').html("Suggest changes"); $('.thank-you-message').css("display","none"); $('.improve-modal--improvement').hide(); $('.improve-modal--suggestion').show(); $('#suggestion-section-textarea').show(); jQuery('#suggestion-modal-alert').hide(); if(suggestEditorInstance !== null){ suggestEditorInstance.setEditorValue(""); } $('.suggestion-section').css('display', 'block'); jQuery('.suggest-bottom-btn').css("display","block"); }); $('.create-improvement_wrapper').on('click',function(){ // when create improvement option clicked then improvement reason will be shown if(loginData && loginData.isLoggedIn) { $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status) }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ } $('.improve-modal--improvement').show(); }); const showErrorMessage = (result,statusCode) => { if(!result) return; $('.spinner-loading-overlay:eq(0)').remove(); if(statusCode == 403) { $('.improve-modal--improve-content.error-message').html(result.message); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); return; } } function suggestionCall() { var editorValue = suggestEditorInstance.getValue(); var suggest_val = $(".ContentEditable__root").find("[data-lexical-text='true']").map(function() { return $(this).text().trim(); }).get().join(' '); suggest_val = suggest_val.replace(/\s+/g, ' ').trim(); var array_String= suggest_val.split(" ") //array of words var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(editorValue.length { jQuery('.ContentEditable__root').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // script for grecaptcha loaded in loginmodal.html and call function to set the token setGoogleRecaptcha(); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status); }, }); });
"For an ad-free experience and exclusive features, subscribe to our Premium Plan!"
Continue without supporting
`; $('body').append(adBlockerModal); $('body').addClass('body-for-ad-blocker'); const modal = document.getElementById("adBlockerModal"); modal.style.display = "block"; } function handleAdBlockerClick(type){ if(type == 'disabled'){ window.location.reload(); } else if(type == 'info'){ document.getElementById("ad-blocker-div").style.display = "none"; document.getElementById("ad-blocker-info-div").style.display = "flex"; handleAdBlockerIconClick(0); } } var lastSelected= null; //Mapping of name and video URL with the index. const adBlockerVideoMap = [ ['Ad Block Plus','https://media.geeksforgeeks.org/auth-dashboard-uploads/abp-blocker-min.mp4'], ['Ad Block','https://media.geeksforgeeks.org/auth-dashboard-uploads/Ad-block-min.mp4'], ['uBlock Origin','https://media.geeksforgeeks.org/auth-dashboard-uploads/ub-blocke-min.mp4'], ['uBlock','https://media.geeksforgeeks.org/auth-dashboard-uploads/U-blocker-min.mp4'], ] function handleAdBlockerIconClick(currSelected){ const videocontainer = document.getElementById('ad-blocker-info-div-gif'); const videosource = document.getElementById('ad-blocker-info-div-gif-src'); if(lastSelected != null){ document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.backgroundColor = "white"; document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.borderColor = "#D6D6D6"; } document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.backgroundColor = "#D9D9D9"; document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.borderColor = "#848484"; document.getElementById('ad-blocker-info-div-name-span').innerHTML = adBlockerVideoMap[currSelected][0] videocontainer.pause(); videosource.setAttribute('src', adBlockerVideoMap[currSelected][1]); videocontainer.load(); videocontainer.play(); lastSelected = currSelected; }

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences