{"id":85196,"date":"2021-10-05T10:19:54","date_gmt":"2021-10-05T04:49:54","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=85196"},"modified":"2026-06-03T15:40:13","modified_gmt":"2026-06-03T10:10:13","slug":"python-hangman-word-guessing-game","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/","title":{"rendered":"Python Hangman Game &#8211; Word Guessing Game"},"content":{"rendered":"<p>In this Python project, we will build a GUI-based Hangman game using the Tkinter, random, screeninfo and PIL modules. It is an intermediate level project, and you will get to use many modules and apply them in real life. Let\u2019s get started!<\/p>\n<h3>About Hangman game:<\/h3>\n<p>A hangman game is the first game that most programmers make, but they make it command-line based, and we are going to make it GUI based. In this game, you need to guess the letters of a word in only a limited number of guesses, or you lose and a man dies!<\/p>\n<h3>About the project:<\/h3>\n<p>The objective of this project is to create a GUI based Hangman game. To build this, you will need intermediate understanding of Tkinter library and PIL\u2019s GUI elements, and basic understanding of the random and screeninfo libraries.<\/p>\n<h3>Project Prerequisites:<\/h3>\n<p>To build this project, we will need the following libraries:<\/p>\n<p><strong>1. Tkinter &#8211;<\/strong> To create the GUI.<br \/>\n<strong>2. PIL (Pillow) &#8211;<\/strong> This is Python\u2019s Image Library used for image manipulation. Here, we will use it to convert the Hangman progress images to PhotoImage format, which allows them to be displayed on Tkinter.<br \/>\n<strong>3. screeninfo.get_monitors() &#8211;<\/strong> To get the info of the screen\u2019s dimension to set the height and width of the GUI window and its elements.<br \/>\n<strong>4. random.choice() &#8211;<\/strong> To get a random word from our list that the user of the game will guess.<br \/>\n<strong>5. os &#8211;<\/strong> To exit the script.<\/p>\n<p>Some of the libraries do not come pre-installed with Python, so you will have to type the following command in your CMD to install them:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">python -m pip install pillow screeninfo\r\n\r\n<\/pre>\n<p>The python wrapper is used because the pip command alone is not supported by some computers.<\/p>\n<h3>Download Python Hangman Project code<\/h3>\n<p>You can download python source code for the hangman word guessing game from the following link: <a href=\"https:\/\/drive.google.com\/file\/d\/1O2OWdgraaNSEJJbZrnyZn_LHF65r3Z6f\/view?usp=drive_link\"><strong>Hangman Project Code<\/strong><\/a><\/p>\n<h3>Tkinter Elements used:<\/h3>\n<p>1. The <strong>Tk()<\/strong> class is used to initialize a GUI window. The attributes and methods that need to be set during initialization are:<br \/>\n<strong>a. .title() method<\/strong> is used to set a title to the window.<br \/>\n<strong>b. .geometry() method<\/strong> is used to set the geometry of the window.<br \/>\n<strong>c. .resizable() method<\/strong> is used to allow\/forbid the user to resize the window.<br \/>\n<strong>d. .update()<\/strong> <strong>and .mainloop() methods<\/strong> are used to prevent the window from closing milliseconds after it opens.<br \/>\nNote: These are the last lines that will be executed that edit the window in any way.<br \/>\n2. The <strong>Label<\/strong> widget is used to display static text to the window.<br \/>\na. The image parameter is used to specify the PhotoImage object that will be used in place of\/along with text in the Label.<br \/>\n3. The <strong>Button<\/strong> class is used to add a button to the window that executes a function as a command when pressed.<br \/>\na. The command parameter is the function to be executed when the button is pressed.<br \/>\n4. The <strong>.place()<\/strong> method is used to place the widget it is associated with as though it is on a Cartesian plane.<br \/>\na. The anchor parameter specifies the origin of the Cartesian for that widget. It can be a corner or a side of the root window.<br \/>\nb. The relx, rely parameters are used to set the horizontal and vertical offsets of the widget as a float number between 0.0 and 1.0<br \/>\nc. The x, y parameters are used to set the horizontal and vertical offsets of the widget<\/p>\n<ul>\n<li>The master parameter is the parent widget of the class it is associated with.<\/li>\n<li>The text parameter is the text to be displayed.<\/li>\n<li>The font parameter is used to specify the font family and effects to the text.<\/li>\n<li>The bg parameter is used to give a background color.<\/li>\n<\/ul>\n<h3>Project File Structure:<\/h3>\n<p>These are the files used in this project:<br \/>\n<strong>1. main.py<\/strong> &#8211; This will be our main python file.<br \/>\n<strong>2. words.txt<\/strong> &#8211; This is the word file where all the words to guess will be there.<br \/>\n<strong>3. Steps<\/strong> <strong>Images (folder):<\/strong> In this folder, we have kept all the progress images that will be displayed as the user guesses an incorrect letter<br \/>\n<strong>a. Step 0.png &#8211;<\/strong> Image to be displayed in the beginning where only the basic setup is visible.<br \/>\n<strong>b. Step 1.png &#8211;<\/strong> Image to be displayed after 1 incorrect guess. No body part is visible.<br \/>\n<strong>c. Step 2.png &#8211;<\/strong> Image to be displayed after 2 incorrect guesses. Only the head is visible.<br \/>\n<strong>d. Step 3.png &#8211;<\/strong> Image to be displayed after 3 incorrect guesses. The torso appears.<br \/>\n<strong>e. Step 4.png &#8211;<\/strong> Image to be displayed after 4 incorrect guesses. The arms appear.<br \/>\n<strong>f. Step 5.png &#8211;<\/strong> Image to be displayed after 5 incorrect guesses. The legs appear and Man gets scared!<br \/>\n<strong>g. Step 6.png &#8211;<\/strong> Image to be displayed after the sixth incorrect guess. Man is hung in this step and the user loses!<br \/>\n<strong>h. Winner.png &#8211;<\/strong> Image to be displayed after the user has successfully guessed the word with 1 or more incorrect guesses remaining. A banner with Congratulations appears, and man thanks you for saving his life.<br \/>\nNote: All the images were created using Fotor.<\/p>\n<p>Here are the steps you will need to execute to build this project:<br \/>\n1. Importing all the necessary modules<br \/>\n2. Setting the variables and getting the monitor\u2019s height and width<br \/>\n3. Creating all the functions<br \/>\n4. Initializing the GUI window, placing components in it and asking if the user wants to play or not<\/p>\n<p>Let\u2019s take a closer look at these steps:<\/p>\n<h4>1. Importing all the necessary modules:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from tkinter import *\r\nimport tkinter.messagebox as mb\r\n\r\nfrom PIL import ImageTk, Image\r\nfrom screeninfo import get_monitors\r\nfrom random import choice\r\nfrom os import system\r\n<\/pre>\n<p><strong>Explanation:<\/strong><\/p>\n<ul>\n<li>The <strong>get_monitors()<\/strong> function will be used to get the information of the local machine\u2019s monitors.<\/li>\n<li>The <strong>system()<\/strong> function will be used (here) only to rerun our Python file if the user decides to reset the game.<\/li>\n<\/ul>\n<h4>2. Setting the variables and getting the monitor\u2019s height and width:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Variables\r\nbuttons_details = [[\"a\", \"A\", 25, 800], [\"b\", \"B\", 125, 800], [\"c\", \"C\", 225, 800], [\"d\", \"D\", 325, 800], [\"e\", \"E\", 425, 800], [\"f\", \"F\", 525, 800], [\"g\", \"G\", 625, 800], ['h', \"H\", 725, 800], ['i', \"I\", 825, 800], ['j', \"J\", 925, 800], ['k', \"K\", 1025, 800], ['l', \"L\", 1125, 800], ['m', \"M\", 1225, 800], ['n', \"N\", 25, 900], ['o', \"O\", 125, 900], ['p', \"P\", 225, 900], ['q', \"Q\", 325, 900], ['r', \"R\", 425, 900], ['s', \"S\", 525, 900], ['t', \"T\", 625, 900], ['u', \"U\", 725, 900], ['v', \"V\", 825, 900], ['w', \"W\", 925, 900], ['x', \"X\", 1025, 900], ['y', \"Y\", 1125, 900], ['z', \"Z\", 1225, 900]]\r\n\r\nword = get_word()\r\nword_length = len(word)-1\r\n\r\ncorrect_guesses = 0\r\nincorrect_guesses = 0\r\n\r\nli_word = [char.upper() for char in word]\r\n# Getting the computer screen's dimensions\r\nmonitor = get_monitors()[0]\r\n\r\nwidth = monitor.width - 600\r\nheight = monitor.height - 100\r\n<\/pre>\n<p><strong>Explanation:<\/strong><\/p>\n<ul>\n<li>We will define the get_word function later.<\/li>\n<li>Slice the get_monitors() so that we can get the dimensions of the monitor that we are using.<\/li>\n<li>We decreased the width and height so the game doesn\u2019t go into full screen mode and hides the taskbar.<\/li>\n<li>The <em>incorrect_guesses<\/em> and <em>correct_guesses<\/em> are used to keep a counter as to how many correct and incorrect guesses have been made by the user.<\/li>\n<li>We have decremented the value of <em>word_length<\/em> by 1 because in our words.txt file, the last character of all the words is a blank space by default.<\/li>\n<\/ul>\n<h4>3. Creating all the functions:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Basic Hangman functions\r\ndef get_word():\r\n   words = []\r\n\r\n   with open('words.txt', 'r') as wordlist:\r\n       for line in wordlist:\r\n           words.append(line)\r\n\r\n   chosen_word = choice(words)\r\n\r\n   return chosen_word\r\n\r\n\r\ndef main_function(btn: Button):\r\n   global image_lbl, li_word, correct_guesses, incorrect_guesses\r\n   global step_1, step_2, step_3, step_4, step_5, step_6\r\n\r\n   if btn['text'] in li_word:\r\n       btn.config(bg='SpringGreen', fg='Black')\r\n       indices = [indx for indx, val in enumerate(li_word) if val == btn['text']]\r\n       for index in indices:\r\n           exec(f'ltr_{index}[\"text\"] = btn[\"text\"]')\r\n           correct_guesses += 1\r\n\r\n   else:\r\n       btn.config(bg='Red', fg='White')\r\n       incorrect_guesses += 1\r\n       exec(f'image_lbl.config(image=step_{incorrect_guesses})')\r\n\r\n   btn.config(state='disabled')\r\n\r\n   if correct_guesses == word_length:\r\n       image_lbl.config(image=won_image)\r\n       mb.showinfo('Congratulations!', 'You have won!\\nMan was right to believe you and you have proved it!\\nCongratulations!')\r\n       root.destroy()\r\n\r\n   if incorrect_guesses == 6:\r\n       mb.showerror('Man\\'s dead!', 'Man counted on you to save him, and you have let him down!')\r\n       root.destroy()\r\n\r\n\r\n# Command functions for the buttons at the top-right of the screen\r\ndef instructions():\r\n   mb.showinfo('',\r\n\"\"\"The instructions are simple:\r\nYou have 6 chances of saving Man, if you get 6 incorrect guesses while trying to guess the detective's word, Man's going to be hung.\r\nIf you make less than 6 incorrect guesses while guessing the word, you will be successful in saving Man's life and he will be eternally grateful to you.\"\"\")\r\n\r\n\r\ndef end_game():\r\n   surety = mb.askyesno('', 'Are you sure you want to exit the game? \\nYour progress will not be saved')\r\n\r\n   if surety:\r\n       root.destroy()\r\n\r\n\r\ndef reset():\r\n   surety = mb.askyesno('', \"Are you sure you want to reset your game?\")\r\n\r\n   if surety:\r\n       root.destroy()\r\n       system('python main.py')\r\n<\/pre>\n<p><strong>Explanation:<\/strong><\/p>\n<ul>\n<li>In this step, we will create all the functions used in our game.<\/li>\n<li>The <em><strong>instructions()<\/strong><\/em> function simply displays a <em><strong>mb.showinfo()<\/strong><\/em> box detailing some of the rules and instructions of the game.<\/li>\n<li>The <em><strong>reset()<\/strong><\/em> function asks the user if they really want to reset the game using a <strong><em>mb.askyesno()<\/em><\/strong> box. If they want to, we will destroy our root window, and use the <strong><em>system()<\/em><\/strong> function of the OS library to rerun our main.py python file.\n<ul>\n<li>How <strong><em>mb.askyesno()<\/em><\/strong> works is that if the user presses the \u201cYes\u201d button, it returns <strong><em>True<\/em><\/strong> and returns <strong><em>False<\/em><\/strong> if the \u201cNo\u201d button is pressed.<\/li>\n<\/ul>\n<\/li>\n<li>The <em><strong>end_game()<\/strong><\/em> function does the same thing as the reset() function, but if the user wants to end the game, we will use the built-in <strong><em>exit()<\/em><\/strong> function to end our Python then-and-there.<\/li>\n<li>In the <strong><em>get_word()<\/em><\/strong> function, we will parse through our word.txt file by opening it in the read mode and store all the words in the file (lines) in a list.<br \/>\nThe word for our game will be a word that will be chosen at random by the <strong><em>choice()<\/em><\/strong> function of the <strong>random<\/strong> library, which the user will need to guess.<\/li>\n<li>Our <strong><em>main()<\/em><\/strong> function, which will essentially do everything to be done when a user presses any letter button, might seem complex, but is very easy once comprehended.\n<ul>\n<li>Whenever the user presses any button, the button will record itself as the argument to its command parameter\u2019s argument (any function) [We\u2019ll get into it later when we talk about the GUI window].<\/li>\n<li>In this function, we will firstly get all the PhotoImage objects and variables to be usable in the function using the global keyword.<\/li>\n<li>Then, we will check if btn[\u201ctext\u201d] (text inside the button) is an element in li_word (the list form of our word), and if it is, we will make that button\u2019s bg color as Spring Green and get all the indices where that letter is present in the word.<br \/>\nThen we will parse through that list of indices we made earlier, and change the text of the corresponding letter Label to the character of the word, thus revealing it and we will increment the value of correct_guesses by one.<\/li>\n<li>If the button pressed isn\u2019t in the word, then it will turn red and we will increment the value of incorrect_guesses by one, and change the PhotoImage object visible to one that shows the next step.<\/li>\n<li>After this conditional pair, we will configure the button to disable, meaning that it can no longer be pressed.<\/li>\n<li>Eventually, if the value of correct_guesses is equal to the length of our word, the user will win and the image will change accordingly. And if the value of incorrect_guesses maximises, the user will lose and Man will die.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>4. Initializing the GUI window, placing components in it and asking if the user wants to play or not:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Initializing the window\r\nroot = Tk()\r\nroot.title('TechVidvan Python Hangman')\r\nroot.geometry(f'{width}x{height}')\r\nroot.resizable(0, 0)\r\nroot.config(bg='White')\r\n\r\n\r\n# Title Label\r\nLabel(text='TechVidvan Python Hangman Game', font=(\"Comic Sans MS\", 22), bg='White').place(relx=0.25, y=0)\r\n\r\n# Asking if the user wants to play\r\nstart_ques = mb.askyesno('Storyline',\r\n'''Man -- yes, that's his name -- has been wrongfully imprisoned and is about to be given the capital punishment.\r\nHowever, the old detective came across some proof that proves Man is innocent. So, the detective wants Man to decide\r\nhis fate and has asked Man to guess a random word he has chosen fully aware that Man himself cannot guess this word\r\nbecause it is too tough for him. And Man has asked you to guess this word for him, and has literally given his life to you.\r\nYou will have 6 lifelines to save Man. If you get 6 incorrect guesses, Man's dead but if you get the word before\r\nthese lifelines end, Man will live and be eternally grateful to you.\r\n\\nWhat do you say, feeling like saving an innocent's life today?''')\r\n\r\nif not start_ques:\r\n   root.destroy()\r\n   exit()\r\n\r\n# Creating all the steps images in PhotoImage format\r\nstep_0 = ImageTk.PhotoImage(Image.open('Steps Images\/Step 0.png'))\r\nstep_1 = ImageTk.PhotoImage(Image.open('Steps Images\/Step 1.png'))\r\nstep_2 = ImageTk.PhotoImage(Image.open('Steps Images\/Step 2.png'))\r\nstep_3 = ImageTk.PhotoImage(Image.open('Steps Images\/Step 3.png'))\r\nstep_4 = ImageTk.PhotoImage(Image.open('Steps Images\/Step 4.png'))\r\nstep_5 = ImageTk.PhotoImage(Image.open('Steps Images\/Step 5.png'))\r\nstep_6 = ImageTk.PhotoImage(Image.open('Steps Images\/Step 6.png'))\r\nwon_image = ImageTk.PhotoImage(Image.open('Steps Images\/Winner.png'))\r\n\r\nimage_lbl = Label(root, image=step_0, bg='White')\r\nimage_lbl.place(relx=0.15, rely=0.1)\r\n\r\n# Placing the word on the window\r\nLabel(root, text='Word to guess:', font=(\"Georgia\", 20, 'bold'), bg='White').place(relx=0.635, rely=0.4)\r\n\r\nx = 0.6\r\ni = 0\r\nwhile i &lt; word_length:\r\n   exec(f'''ltr_{i} = Label(root, text=\"_\", bg=\"White\", font=(\"Georgia\", 30)); ltr_{i}.place(relx={x}, rely=0.45)''')\r\n   x += 0.03\r\n   i += 1\r\n\r\n# Creating all the letter buttons\r\nfor button in buttons_details:\r\n   exec(f'''{button[0]}_btn = Button(root, text=button[1], width=8, height=2, bg=\"DeepSkyBlue\",\r\n        command=lambda: main_function({button[0]}_btn))''')\r\n   exec(f'{button[0]}_btn.place(x=button[2], y=button[3])')\r\n\r\nButton(root, text='INSTRUCTIONS', font=(\"PlayfairDisplay\", 12, 'bold'), bg='DeepSkyBlue',\r\n      command=instructions).place(x=1125, y=100)\r\n\r\nButton(root, text='EXIT', font=(\"PlayfairDisplay\", 12, 'bold'), width=13, bg='DeepSkyBlue',\r\n      command=end_game).place(x=1125, y=175)\r\n\r\nButton(root, text='RESET', font=(\"PlayfairDisplay\", 12, 'bold'), width=13, bg='DeepSkyBlue',\r\n      command=reset).place(x=1125, y=250)\r\n\r\n# Finalizing the window\r\nroot.mainloop()\r\n<\/pre>\n<p><strong>Explanation:<\/strong><\/p>\n<ul>\n<li>In this step, we will create our GUI window of the game.<\/li>\n<li>After we define the heading label, we will provide the user with a storyline and ask if they want to play. If they do, we will continue but if they don\u2019t, we\u2019ll use <strong><em>exit()<\/em><\/strong> function to end our script.<\/li>\n<li>Then we will open our images in the <strong>\u201cSteps Images\u201d<\/strong> folder and convert them to PhotoImage objects which will be displayed by the image_lbl, which is a Label widget.<\/li>\n<li>We will then place the word on the window, towards the right of the image in the form of underscores to denote the number of characters it is.<\/li>\n<li>At the bottom side, we will have all the buttons that the user needs to press in order for the game to progress.\n<ul>\n<li>The built-in <strong><em>exec()<\/em><\/strong> is used to execute what is provided to it as an argument as a python script.<\/li>\n<li>The button_details variable that we defined earlier contains the latter part of the variable name, text to be displayed,<\/li>\n<li>x-offset and y-offset of the button respectively in each nested list.<br \/>\nUsing the exec() function, we will successfully create all the buttons and provide those buttons as arguments to the function we put in in the command parameter while defining the button.<\/li>\n<\/ul>\n<\/li>\n<li>On the top right side of the window, we have 3 buttons that will execute the instructions(), reset(), and end_game() functions when pressed.<\/li>\n<\/ul>\n<h3>Python Hangman Game Output<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/10\/python-hangman-game-beginning.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-85375\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/10\/python-hangman-game-beginning.webp\" alt=\"python hangman game beginning\" width=\"1322\" height=\"1019\" \/><\/a><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/10\/hangman-game-won.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-85376\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/10\/hangman-game-won.webp\" alt=\"hangman game won\" width=\"1326\" height=\"1018\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>Congratulations! You have now created your own GUI based Hangman game using the Tkinter, random, screeninfo and the PIL modules. This is an incredible pass time that also enhances your vocabulary and you get to be a superhero who saved an innocent\u2019s life!<\/p>\n<p>Have fun coding! \ud83d\ude0a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Python project, we will build a GUI-based Hangman game using the Tkinter, random, screeninfo and PIL modules. It is an intermediate level project, and you will get to use many modules and&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":85367,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1053],"tags":[4385,4386,4387,4388,4389,483,4390],"class_list":["post-85196","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python-game","tag-python-game-project","tag-python-guess-words","tag-python-hangman","tag-python-hangman-game","tag-python-project","tag-word-guessing-game"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Hangman Game - Word Guessing Game - TechVidvan<\/title>\n<meta name=\"description\" content=\"Build a GUI-based Hangman game using the Tkinter, random, screeninfo and PIL modules. Source code is provided for your help.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Hangman Game - Word Guessing Game - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Build a GUI-based Hangman game using the Tkinter, random, screeninfo and PIL modules. Source code is provided for your help.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-05T04:49:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-03T10:10:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/10\/python-project-hangman-game.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=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Hangman Game - Word Guessing Game - TechVidvan","description":"Build a GUI-based Hangman game using the Tkinter, random, screeninfo and PIL modules. Source code is provided for your help.","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:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/","og_locale":"en_US","og_type":"article","og_title":"Python Hangman Game - Word Guessing Game - TechVidvan","og_description":"Build a GUI-based Hangman game using the Tkinter, random, screeninfo and PIL modules. Source code is provided for your help.","og_url":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-10-05T04:49:54+00:00","article_modified_time":"2026-06-03T10:10:13+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/10\/python-project-hangman-game.webp","type":"image\/webp"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Python Hangman Game &#8211; Word Guessing Game","datePublished":"2021-10-05T04:49:54+00:00","dateModified":"2026-06-03T10:10:13+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/"},"wordCount":1844,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/10\/python-project-hangman-game.webp","keywords":["python game","python game project","python guess words","python hangman","python hangman game","Python project","word guessing game"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/","url":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/","name":"Python Hangman Game - Word Guessing Game - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/10\/python-project-hangman-game.webp","datePublished":"2021-10-05T04:49:54+00:00","dateModified":"2026-06-03T10:10:13+00:00","description":"Build a GUI-based Hangman game using the Tkinter, random, screeninfo and PIL modules. Source code is provided for your help.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/10\/python-project-hangman-game.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/10\/python-project-hangman-game.webp","width":1200,"height":628,"caption":"python project hangman game"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/python-hangman-word-guessing-game\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Python Hangman Game &#8211; Word Guessing Game"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/85196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=85196"}],"version-history":[{"count":1,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/85196\/revisions"}],"predecessor-version":[{"id":448104,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/85196\/revisions\/448104"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/85367"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=85196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=85196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=85196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}