

{"id":108122,"date":"2022-03-15T09:00:35","date_gmt":"2022-03-15T03:30:35","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=108122"},"modified":"2026-06-01T14:05:16","modified_gmt":"2026-06-01T08:35:16","slug":"python-tetris-game-pygame","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/","title":{"rendered":"Python Tetris Game &#8211; Develop Tetris using PyGame"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:2588,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1BRmiMzTXTg8a4lzbvuKgDBKyYNFfKKZh\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20260601085153\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1BRmiMzTXTg8a4lzbvuKgDBKyYNFfKKZh\\\/view?usp=drive_link&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-06-02 07:17:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-06 09:31:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-12 14:19:12&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-12 14:19:12&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>Have you ever played the Tetris puzzle? It is a video game that is developed with a motive to get an order out of chaos. It helps in improving both thinking and learning skills. Wouldn\u2019t it be interesting to build this game in Python? So, let\u2019s start.<\/p>\n<h3>What is Tetris?<\/h3>\n<p>The Tetris game consists of blocks\/tetriminos, of different shapes. that appear one after another. And the objective is to place these blocks on the screen such that we form rows at the bottom of the board.<\/p>\n<p>Every completed row increases the score. To do so, the player will be allowed to move the falling block to left, right, down and also rotate it using the keyboard buttons.<\/p>\n<h3>Python Tetris &#8211; Project details<\/h3>\n<p>To build this game we will be using the Pygame module in Python. We will also use the random module to select the shape and color of the Tetrimino. And we consider the whole game board and the blocks as matrices. This makes it easy to do the operations, shifting, and rotation.<\/p>\n<h3>Download Python Tetris Code<\/h3>\n<p>Please download the code for the Tetris game here: <a href=\"https:\/\/drive.google.com\/file\/d\/1BRmiMzTXTg8a4lzbvuKgDBKyYNFfKKZh\/view?usp=drive_link\"><strong>Python Tetris Game Project Source Code<\/strong><\/a><\/p>\n<h3>Project Prerequisites<\/h3>\n<p>It is suggested to have prior knowledge on Python and PyGame. If you don\u2019t have the PyGame module, then you can install it using the following command.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip install pygame\r\n\r\n<\/pre>\n<h3>Steps to build the Python Tetris Game<\/h3>\n<p>We are done discussing the necessities of the project, let us look into the steps to be followed to build the project.<\/p>\n<p>1. Create a matrix storing the information about the block and write a class to handle these details.<\/p>\n<p>2. Create a class to handle the creation of blocks, their movement, and placement.<\/p>\n<p>3. Create the main window for the game.<\/p>\n<p>4. Keep checking the button pressed and the status of the blocks in the board.<\/p>\n<p>5. End the game when the blocks touch the top of the board.<\/p>\n<p>This game is written in an infinite while loop that runs till the fifth condition above is met.<\/p>\n<h3>1. Importing the required modules<\/h3>\n<p>We are importing the pygame module which we use to build the Tetris game and then importing the random module to get the shapes of the blocks in a random manner.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import pygame\r\nimport random\r\n<\/pre>\n<h3>2. Creating variables to store shapes and colors of the blocks<\/h3>\n<p>In the below code, the shapes variable holds the matrix that contains information about the shape of the block. Assume a 4&#215;4 block and give each cell indices as shown below<\/p>\n<table style=\"height: 214px\" width=\"259\">\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">0<\/span><\/td>\n<td><span style=\"font-weight: 400\">1<\/span><\/td>\n<td><span style=\"font-weight: 400\">2<\/span><\/td>\n<td><span style=\"font-weight: 400\">3<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4<\/span><\/td>\n<td><span style=\"font-weight: 400\">5<\/span><\/td>\n<td><span style=\"font-weight: 400\">6<\/span><\/td>\n<td><span style=\"font-weight: 400\">7<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">8<\/span><\/td>\n<td><span style=\"font-weight: 400\">9<\/span><\/td>\n<td><span style=\"font-weight: 400\">10<\/span><\/td>\n<td><span style=\"font-weight: 400\">11<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">12<\/span><\/td>\n<td><span style=\"font-weight: 400\">13<\/span><\/td>\n<td><span style=\"font-weight: 400\">14<\/span><\/td>\n<td><span style=\"font-weight: 400\">15<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400\">Then, [1, 5, 9, 13] represents the vertical line (second column),\u00a0 [1, 5, 9, 8] represents L shape, etc. And the shapeColors hold the RGB values of different colors from which we randomly select a color for a block.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#Shapes of the blocks\r\nshapes = [\r\n        [[1, 5, 9, 13], [4, 5, 6, 7]],\r\n        [[4, 5, 9, 10], [2, 6, 5, 9]],\r\n        [[6, 7, 9, 10], [1, 5, 6, 10]],\r\n        [[1, 2, 5, 9], [0, 4, 5, 6], [1, 5, 9, 8], [4, 5, 6, 10]],\r\n        [[1, 2, 6, 10], [5, 6, 7, 9], [2, 6, 10, 11], [3, 5, 6, 7]],\r\n        [[1, 4, 5, 6], [1, 4, 5, 9], [4, 5, 6, 9], [1, 5, 6, 9]],\r\n        [[1, 2, 5, 6]],\r\n    ]\r\n#Colors of the blocks\r\nshapeColors = [(0, 255, 0), (255, 0, 0), (0, 255, 255), (255, 255, 0), (255, 165, 0), (0, 0, 255), (128, 0, 128)]\r\n<\/pre>\n<h3>3. Creating a class Blocks to hold information about the current block<\/h3>\n<p>This class assigns the coordinates, shape, color and rotation to the block object created. Using the function random.randint(), which generates a random integer in the given range, a random shape and color are assigned to a block.<\/p>\n<p>The function rotate() gives the index of the rotation variant of a given shape from the matrix \u2018shapes\u2019. And the function image() returns the rotated variant block to the Block object.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># GLOBALS VARS\r\nwidth = 700\r\nheight = 600\r\ngameWidth = 100  \r\ngameHeight = 400 \r\nblockSize = 20\r\n \r\ntopLeft_x = (width - gameWidth) \/\/ 2\r\ntopLeft_y = height - gameHeight - 50\r\n\r\n\r\nclass Block:\r\n    x = 0\r\n    y = 0\r\n    n = 0\r\n    def __init__(self, x, y,n):\r\n        self.x = x\r\n        self.y = y\r\n        self.type = n\r\n        self.color = n\r\n        self.rotation = 0\r\n    def image(self):\r\n        return shapes[self.type][self.rotation]\r\n\r\n    def rotate(self):\r\n        self.rotation = (self.rotation + 1) % len(shapes[self.type])\r\n<\/pre>\n<h3>4. Creating a class Tetris for creation of blocks, controlling their movement and placement<\/h3>\n<p>In this class, we first create variables that set the properties of the board and also set the score to 0 and state to \u201cstart\u201d. The field variable stores the board in the form of a 2D matrix.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># GLOBALS VARS\r\nwidth = 700\r\nheight = 600\r\ngameWidth = 100  \r\ngameHeight = 400 \r\nblockSize = 20\r\n \r\ntopLeft_x = (width - gameWidth) \/\/ 2\r\ntopLeft_y = height - gameHeight - 50\r\n\r\n\r\nclass Block:\r\n    x = 0\r\n    y = 0\r\n    n = 0\r\n    def __init__(self, x, y,n):\r\n        self.x = x\r\n        self.y = y\r\n        self.type = n\r\n        self.color = n\r\n        self.rotation = 0\r\n    def image(self):\r\n        return shapes[self.type][self.rotation]\r\n\r\n    def rotate(self):\r\n        self.rotation = (self.rotation + 1) % len(shapes[self.type])\r\n<\/pre>\n<p>In the following code, which is a part of the Tetris class, has the below functions<\/p>\n<p><span style=\"font-weight: 400\">1. The new_block() function creates a new block using the Block() class.<\/span><\/p>\n<p><span style=\"font-weight: 400\">2. The function next_block() creates the next block that would be appearing on the screen.\u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">3. The intersects() function checks if the blocks touch the top of the board. This decides the end of the game.<\/span><\/p>\n<p><span style=\"font-weight: 400\">4. The break_lines() function checks if the blocks form any row. If the condition is met, then it increases the score and deletes the line.<\/span><\/p>\n<p><span style=\"font-weight: 400\">5. And the function draw_next_block() places the next block beside the main game to show it to the player.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#Creates a new block\r\n    def new_block(self):\r\n        self.block = Block(3, 0,random.randint(0, len(shapes) - 1))\r\n                           \r\n    def next_block(self):\r\n        self.nextBlock=Block(3,0,random.randint(0, len(shapes) - 1))\r\n    #Checks if the blocks touch the top of the board\r\n    def intersects(self):\r\n        intersection = False\r\n        for i in range(4):\r\n            for j in range(4):\r\n                if i * 4 + j in self.block.image():\r\n                    if i + self.block.y &gt; self.height - 1 or \\\r\n                            j + self.block.x &gt; self.width - 1 or \\\r\n                            j + self.block.x &lt; 0 or \\\r\n                            self.field[i + self.block.y][j + self.block.x] &gt; 0:\r\n                        intersection = True\r\n        return intersection\r\n\r\n    #Checks if a row is formed and destroys that line\r\n    def break_lines(self):\r\n        lines = 0\r\n        for i in range(1, self.height):\r\n            zeros = 0\r\n            for j in range(self.width):\r\n                if self.field[i][j] == 0:\r\n                    zeros += 1\r\n            if zeros == 0:\r\n                lines += 1\r\n                for i1 in range(i, 1, -1):\r\n                    for j in range(self.width):\r\n                        self.field[i1][j] = self.field[i1 - 1][j]\r\n        self.score += lines ** 2\r\n\r\ndef draw_next_block(self,screen):\r\n    \r\n        font = pygame.font.SysFont(\"Calibri\", 30)\r\n        label = font.render(\"Next Shape\", 1, (128,128,128))\r\n\r\n        sx = topLeft_x + gameWidth + 50\r\n        sy = topLeft_y + gameHeight\/2 - 100\r\n        format = self.nextBlock.image()\r\n        for i in range(4):\r\n                for j in range(4):\r\n                    p = i * 4 + j\r\n                    if p in self.nextBlock.image():\r\n                        pygame.draw.rect(screen, shapeColors[self.nextBlock.color],(sx + j*30, sy + i*30, 30, 30), 0)\r\n<\/pre>\n<p><span style=\"font-weight: 400\">Now it&#8217;s time to write the functions to move the blocks.<\/span><\/p>\n<p><span style=\"font-weight: 400\">1. The go_down() function moves the block down by a unit<\/span><\/p>\n<p><span style=\"font-weight: 400\">2. The go_space() function is similar to go_down(), but it moves the block down to the bottom<\/span><\/p>\n<p><span style=\"font-weight: 400\">3. The freez() function runs once the block reaches the bottom. And it checks if any row is formed, forms a new block and if it touches the top, it ends the game.<\/span><\/p>\n<p><span style=\"font-weight: 400\">4. The go_side() function moves the block to either right or left<\/span><\/p>\n<p><span style=\"font-weight: 400\">5. And the rotate() function rotates the block by 90 degrees in clockwise or anticlockwise direction<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#Moves the block down by a unit\r\ndef go_down(self):\r\n    self.block.y += 1\r\n    if self.intersects():\r\n        self.block.y -= 1\r\n        self.freeze()\r\n\r\n#Moves the block to the bottom\r\ndef go_space(self):\r\n    while not self.intersects():\r\n        self.block.y += 1\r\n    self.block.y -= 1\r\n    self.freeze()\r\n\r\n# This function runs once the block reaches the bottom. \r\ndef freeze(self):\r\n    for i in range(4):\r\n        for j in range(4):\r\n            if i * 4 + j in self.block.image():\r\n                self.field[i + self.block.y][j + self.block.x] = self.block.color\r\n    self.break_lines() #Checking if any row is formed\r\n    self.new_block() #Creating a new block\r\n    if self.intersects(): #If blocks touch the top of the board, then ending the game by setting status as gameover\r\n        self.state = \"gameover\"\r\n#This function moves the block horizontally\r\ndef go_side(self, dx):\r\n    old_x = self.block.x\r\n    self.block.x += dx\r\n    if self.intersects():\r\n        self.block.x = old_x\r\n#This function rotates the block \r\ndef rotate(self):\r\n    old_rotation = self.block.rotation\r\n    self.block.rotate()\r\n    if self.intersects():\r\n        self.block.rotation = old_rotation\r\n<\/pre>\n<h3>Main game<\/h3>\n<p>It&#8217;s time to create the main window. We do this by using the init() function in PyGame. We also set the other properties like size, and title. When the user presses any of the keyboard buttons, the main game starts.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pygame.font.init()\r\nscreen = pygame.display.set_mode((width, height))\r\npygame.display.set_caption(\"Tetris by DataFlair\")\r\nrun = True\r\nwhile run:\r\n    screen.fill((16, 57, 34 ))\r\n    font = pygame.font.SysFont(\"Calibri\", 70, bold=True)\r\n    label = font.render(\"Press any key to begin!\", True, '#FFFFFF')\r\n\r\n    screen.blit(label, (10, 300 ))\r\n    pygame.display.update()\r\n    for event in pygame.event.get():\r\n        if event.type == pygame.QUIT:\r\n            run = False\r\n        if event.type == pygame.KEYDOWN:\r\n            startGame()\r\npygame.quit()\r\n<\/pre>\n<p><span style=\"font-weight: 400\">Now, write the function startGame()\u00a0 with a for loop that runs infinitely till the game end condition is met. This loop includes the following operations:<\/span><\/p>\n<p><span style=\"font-weight: 400\">1. Creating a new block if there is no moving block.<\/span><\/p>\n<p><span style=\"font-weight: 400\">2. Moving the block down by a unit continuously or when the down key is pressed.<\/span><\/p>\n<p><span style=\"font-weight: 400\">3. Checking the key pressed, if any, and doing the corresponding function discussed above.<\/span><\/p>\n<p><span style=\"font-weight: 400\">4. Updating the board with the previous blocks and the moving block.<\/span><\/p>\n<p><span style=\"font-weight: 400\">5. Checking the status and ending the game if the status is gameover<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def startGame():\r\n    done = False\r\n    clock = pygame.time.Clock()\r\n    fps = 25\r\n    game = Tetris(20, 10)\r\n    counter = 0\r\n\r\n    pressing_down = False\r\n    \r\n    while not done:\r\n        #Create a new block if there is no moving block\r\n        if game.block is None:\r\n            game.new_block()\r\n        if game.nextBlock is None:\r\n            game.next_block()\r\n        counter += 1 #Keeping track of the time \r\n        if counter &gt; 100000:\r\n            counter = 0\r\n\r\n        #Moving the block continuously with time or when down key is pressed\r\n        if counter % (fps \/\/ game.level \/\/ 2) == 0 or pressing_down:\r\n            if game.state == \"start\":\r\n                game.go_down()\r\n        #Checking which key is pressed and running corresponding function\r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT:\r\n                done = True\r\n            if event.type == pygame.KEYDOWN:\r\n                if event.key == pygame.K_UP:\r\n                    game.rotate()\r\n                if event.key == pygame.K_DOWN:\r\n                    game.moveDown()\r\n                if event.key == pygame.K_LEFT:\r\n                    game.moveHoriz(-1)\r\n                if event.key == pygame.K_RIGHT:\r\n                    game.moveHoriz(1)\r\n                if event.key == pygame.K_SPACE:\r\n                    game.moveBottom()\r\n                if event.key == pygame.K_ESCAPE:\r\n                    game.__init__(20, 10)\r\n\r\n        screen.fill('#FFFFFF')\r\n\r\n        #Updating the game board regularly\r\n        for i in range(game.height):\r\n            for j in range(game.width):\r\n                pygame.draw.rect(screen, '#B2BEB5', [game.x + game.zoom * j, game.y + game.zoom * i, game.zoom, game.zoom], 1)\r\n                if game.field[i][j] &gt; 0:\r\n                    pygame.draw.rect(screen, shapeColors[game.field[i][j]],\r\n                                     [game.x + game.zoom * j + 1, game.y + game.zoom * i + 1, game.zoom - 2, game.zoom - 1])\r\n\r\n        #Updating the board with the moving block\r\n        if game.block is not None:\r\n            for i in range(4):\r\n                for j in range(4):\r\n                    p = i * 4 + j\r\n                    if p in game.block.image():\r\n                        pygame.draw.rect(screen, shapeColors[game.block.color],\r\n                                         [game.x + game.zoom * (j + game.block.x) + 1,\r\n                                          game.y + game.zoom * (i + game.block.y) + 1,\r\n                                          game.zoom - 2, game.zoom - 2])\r\n\r\n        #Showing the score\r\n        font = pygame.font.SysFont('Calibri', 40, True, False)\r\n        font1 = pygame.font.SysFont('Calibri', 25, True, False)\r\n        text = font.render(\"Score: \" + str(game.score), True, '#000000')\r\n        text_game_over = font.render(\"Game Over\", True, '#000000')\r\n        text_game_over1 = font.render(\"Press ESC\", True, '#000000')\r\n\r\n        #Ending the game if state is gameover\r\n        screen.blit(text, [300, 0])\r\n        if game.state == \"gameover\":\r\n            screen.blit(text_game_over, [300, 200])\r\n            screen.blit(text_game_over1, [300, 265])\r\n       \r\n        game.draw_next_block(screen)\r\n\r\n        pygame.display.flip()\r\n        clock.tick(fps)    \r\n<\/pre>\n<h3>Python Tetris Game Output<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/python-tetris-game-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-108208\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/python-tetris-game-output.webp\" alt=\"python tetris game output\" width=\"863\" height=\"787\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>With this Python project, we have successfully built the python tetris game. For this, we used the pygame and random libraries. We learned how to create shapes for blocks, capture events from the keyboard and trigger a function. We could also check the status of the Tetris board. Hoping that you enjoyed developing this with us!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever played the Tetris puzzle? It is a video game that is developed with a motive to get an order out of chaos. It helps in improving both thinking and learning skills.&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":108209,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[25791,21082,22734,21099,26689,26659,26660],"class_list":["post-108122","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python-game-project","tag-python-project","tag-python-project-for-beginners","tag-python-project-with-source-code","tag-python-tetris","tag-python-tetris-game-project","tag-python-tetris-game-project-with-source-code"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Tetris Game - Develop Tetris using PyGame - DataFlair<\/title>\n<meta name=\"description\" content=\"Create Tetris Game Project in Python using pygame module to build Tetris game &amp; random module to get shapes of blocks in random manner.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Tetris Game - Develop Tetris using PyGame - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Create Tetris Game Project in Python using pygame module to build Tetris game &amp; random module to get shapes of blocks in random manner.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-15T03:30:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T08:35:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/python-tetris-game-project.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Tetris Game - Develop Tetris using PyGame - DataFlair","description":"Create Tetris Game Project in Python using pygame module to build Tetris game & random module to get shapes of blocks in random manner.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/","og_locale":"en_US","og_type":"article","og_title":"Python Tetris Game - Develop Tetris using PyGame - DataFlair","og_description":"Create Tetris Game Project in Python using pygame module to build Tetris game & random module to get shapes of blocks in random manner.","og_url":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2022-03-15T03:30:35+00:00","article_modified_time":"2026-06-01T08:35:16+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/python-tetris-game-project.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Tetris Game &#8211; Develop Tetris using PyGame","datePublished":"2022-03-15T03:30:35+00:00","dateModified":"2026-06-01T08:35:16+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/"},"wordCount":978,"commentCount":6,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/python-tetris-game-project.webp","keywords":["python game project","Python project","python project for beginners","python project with source code","python tetris","Python Tetris Game Project","Python Tetris Game Project with source code"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/","url":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/","name":"Python Tetris Game - Develop Tetris using PyGame - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/python-tetris-game-project.webp","datePublished":"2022-03-15T03:30:35+00:00","dateModified":"2026-06-01T08:35:16+00:00","description":"Create Tetris Game Project in Python using pygame module to build Tetris game & random module to get shapes of blocks in random manner.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/python-tetris-game-project.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/03\/python-tetris-game-project.webp","width":1200,"height":628,"caption":"python tetris game project"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-tetris-game-pygame\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Tetris Game &#8211; Develop Tetris using PyGame"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":false,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/108122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=108122"}],"version-history":[{"count":6,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/108122\/revisions"}],"predecessor-version":[{"id":148672,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/108122\/revisions\/148672"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/108209"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=108122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=108122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=108122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}