A
Report on
HANGMAN
CS205ES- PYTHON PROGRAMMING PROJECT
Submitted in partial fulfilment of the requirements for
The Award of the degree of
BACHELOR OF TECHNOLOGY
In
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
By
VELAGA BHAVYA VARA GITHIKA- 24K81A66C6
TIRUMALA CHANDRAHAS- 24K81A66C2
ADITI- 24K81A6667
NALLA VILASHITHA- 24K81A66A6
Under the esteemed guidance of
Mr. Akhil.P
ASSISTANT PROFESSOR
DEPARTMENT OF CSE
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
St. MARTIN’S ENGINEERING COLLEGE
UGC AUTONOMOUS
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad – 500100
St. MARTIN’S ENGINEERING COLLEGE
UGC AUTONOMOUS
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad – 500100
College Code: K8
CERTIFICATE
This is certify that the PYTHON PROGRAMMING PROJECT entitled
“HANGMAN” is a bonafide record of group work done by VELAGA
BHAVYA VARA GITHIKA (24K81A66C6), TIRUMALA CHANDRAHAS
(24K81A66C2), ADITI (24K81A6667), NALLA VILASHITHA (24K81A66A6)
under my supervision and guidance, submitted to St. MARTIN’S
ENGINEERING COLLEGE, Hyderabad, in partial fulfilment for the award of
the Degree of Bachelor of Technology in Computer Science and Engineering.
Project Internal Guide Head of Department
Mr. Akhil .P Dr. [Link] Reddy
(Dept. of CSE) (Dept. of FME)
.
ABSTRACT
Games have always played a significant role in enhancing entertainment and learning, and in
today’s digital age, they have become more interactive and accessible than ever. One such game is
Hangman, a classic word-guessing game that has been digitally transformed for a better user
experience. Traditionally, Hangman was played using pen and paper, where one person thinks of
a word and the other guesses it letter by letter, but now it can be played on digital platforms which
makes it more engaging and visually appealing. In our digital version of Hangman, the game starts
with a Start button that initiates the gameplay. Once started, the player is provided with a hint
related to the word, making it easier and more interesting to guess. The word is displayed as blank
spaces, and the player has to guess the letters. For every wrong guess, a part of the Hangman
drawing appears, adding tension and excitement to the game. The drawing completes after a set
number of wrong guesses, signalling the end of the game. This digital Hangman game not only
offers a fun way to play but also helps improve vocabulary and logical thinking, making it both
educational and entertaining.
CONTENTS
ABSTRACT i
CHAPTER 1- INTRODUCTION 1
CHAPTER 2-LITERATURE SURVEY 3
CHAPTER 3-SYSTEM ANALYSIS 9
3.1 Existing System 10
3.2 Proposed System 10
3.3 Hardware Requirements 13
3.4 Software Requirements 13
CHAPTER 4- SYSTEM ARCHITECTURE 22
CHAPTER 5- SYSTEM IMPLEMENTATION 45
CHAPTER 6-SYSTEM TESTING 48
CHAPTER 7-OUTPUT SCREENS 50
CHAPTER 8-CONCLUSION 55
CHAPTER 9-FUTURE ENHANCEMENT 56
CHAPTER 10-REFERENCES 57
CHAPTER 1- INTRODUCTION
This project implements a Hangman game using the Python programming language and the
Tkinter GUI toolkit. It provides an interactive graphical interface where the player tries to guess a
hidden word, one letter at a time, based on a given hint. For every incorrect guess, a part of the
hangman's body is drawn, with the game ending either when the word is fully guessed or the entire
figure is drawn (after 6 incorrect guesses).
This project demonstrates the use of essential Python programming concepts, including control
flow, string manipulation, functions, classes, GUI elements, and event-driven programming.
Control Statements used in this project:
• if-else statements: Used to validate guesses and handle game logic.
• for loop and list comprehensions: Used to update the display of the guessed word and
check win conditions.
The list of the operators used in this project:
• Arithmetic operator: +
• Assignment operator: =
• Comparison operators: ==, !=, <, >=
• Logical operators: and, or, not
• Membership operator: in
The data structures used in this project:
Lists:
• words: A list of tuples used to store word-hint pairs.
• correct_letters: Used to keep track of correctly guessed letters.
• List comprehensions are used to dynamically display the current word progress.
Strings:
• Used for storing and comparing input guesses.
• Used in GUI components for displaying hints, messages, and the word progress.
Tuples:
• Used in the words list to store each word and its corresponding hint.
Functions and Classes:
• The game logic is organized into a class HangmanApp that contains methods like:
o start_game()
o display_game()
o check_guess()
o draw_body_part()
o end_game()
GUI components (Tkinter) used in this project:
• Label: For displaying the game title, hint, and the current word.
• Button: For starting the game and submitting guesses.
• Entry: For user to enter letter guesses.
• Canvas: For drawing the gallows and hangman figure.
• messagebox: For showing instructions and final messages.
This project provides a simple and effective way to learn and apply Python programming along
with GUI development. It is ideal for beginners to get hands-on experience with core
programming logic and event-driven interfaces.
CHAPTER 2-LITERATURE SURVEY
The development of educational and recreational games using Python has been widely supported
through academic texts and online resources. The Hangman game, known for improving
vocabulary and critical thinking, is frequently used as a beginner-level programming project to
teach core Python concepts.
John Zelle’s "Python Programming: An Introduction to Computer Science" (2004) introduces
essential Python programming constructs like loops, conditionals, and string operations —
foundational elements for building simple games such as Hangman. Similarly, "Invent Your Own
Computer Games with Python" by Al Sweigart (2015) provides a beginner-friendly guide to
developing text-based games. The book features a complete tutorial for the Hangman game,
covering modules like random, input handling, and game logic implementation.
Paul Barry’s "Head First Programming" (2009) contributes to problem-solving techniques using
Python in a modular and structured way — skills that align with the design of object-oriented
games. Eric Matthes’ "Python Crash Course" (2016) emphasizes hands-on practice with small
projects, including games that use loops, lists, and conditional statements to control game flow, all
of which are relevant to Hangman.
Guido van Rossum’s ongoing Python Official Documentation is an indispensable reference for
understanding standard libraries such as random, tkinter, and string, which are integral to GUI-
based Hangman game development. Charles Severance’s "Python for Everybody" (2016) provides
strong grounding in user input validation, error handling, and file operations — all crucial when
extending the game with multiplayer features or word banks.
Online tutorials from platforms like W3Schools, GeeksforGeeks, and Programiz offer concise
examples and exercises that helped shape many features of this project, including the user interface
logic, canvas drawing methods, and input validation. Additionally, the Stack Overflow community
serves as a valuable support network for troubleshooting errors and implementing features such as
drawing graphics with Canvas, managing game states, or optimizing loops and conditionals.
These sources collectively support the development of the Hangman game by equipping
developers with a mix of theoretical understanding and practical guidance. The integration of these
concepts into a GUI-based Python application demonstrates how foundational programming
techniques can be applied to build interactive and educational games.
CHAPTER 3-SYSTEM ANALYSIS
Existing System
Traditional implementations of the Hangman game are mostly pen-and-paper based. One player
thinks of a word and draws blank spaces, while the other guesses letters. With each incorrect guess,
a part of the hangman figure is manually drawn. This method is simple but lacks interactivity,
automation, and consistent rule enforcement. There is no built-in tracking for guesses, hints, or
automatic win/loss detection. Also, it is not visually engaging and does not offer reusability or
customization. Mistakes in tracking letters or drawing parts can also disrupt gameplay.
Disadvantages of Existing System
• Completely manual and not interactive
• Requires another person to set up and monitor the game
• Prone to human error in enforcing rules or tracking guesses
• No automatic feedback or hint mechanism
• Not engaging or reusable as a digital game
Proposed System
The proposed system is a digital implementation of the Hangman game using Python programming
language and Tkinter for the graphical user interface. It automates the entire game flow including
word selection, hint display, guess checking, and drawing the hangman figure. The interface is
simple and user-friendly, making it suitable for players of all ages. It uses canvas graphics to
dynamically draw parts of the hangman with each wrong guess and shows visual progress of the
guessed word.
The system displays hints, tracks correct and incorrect letters, and determines game status
automatically. It also offers the option to restart the game or quit. The design is modular and object-
oriented, allowing easy expansion and maintenance. This implementation enhances the traditional
game by making it more accessible, accurate, and interactive.
Advantages of Proposed System
1. Fully automated hangman gameplay
2. Visual drawing of hangman on canvas
3. Hints provided with each word
4. Input validation and guess tracking
5. Automatic win/loss detection
6. Interactive and reusable digital interface
Software Requirements
• Python 3.x
• Tkinter (comes bundled with standard Python installation)
• Code editor (e.g., VS Code, PyCharm, IDLE)
Hardware Requirements
• 512MB RAM or more
• 1GHz Processor
• 50MB free disk space
• Windows/Linux/macOS OS with GUI support
CHAPTER 4- SYSTEM ARCHITECTURE
Algorithm
1. Define a word list containing word-hint pairs (e.g., ("python", "A programming
language")).
2. Create GUI window using Tkinter and define components: title label, start button, canvas
(for drawing), labels for hint and blanks, entry for user input, and submit button.
3. Display the "Start" button on the main screen; wait for user to click it.
4. On button click, show game instructions using a message box with an option to proceed.
5. If user agrees to play:
a) Randomly choose a word and its hint from the list
b) Reset wrong guesses and guessed letters list
c) Draw the hangman gallows on canvas
d) Display the hint, blank spaces, and guess entry box
6. Wait for user to enter a guess in the input field and click the "Guess" button.
7. On guess submission:
a) Validate the guess (only one alphabet letter)
b) If valid and not already guessed:
i) If letter is in word → add to correct guesses
ii) Else → increase wrong guess count and draw next body part
8. After each guess:
a) Update the displayed word with correctly guessed letters
b) If all letters are guessed → show win message
c) If 6 wrong guesses made → show loss message with the correct word
9. When game ends:
a) Hide input and submit button
b) Ask if user wants to play again using a message box
10. If user wants to play again, go back to step 5; else close the application.
11. Repeat steps 6–10 until the user exits.
Flowchart
CHAPTER 5- SYSTEM IMPLEMENTATION
Code:
import tkinter as tk
from tkinter import messagebox
import random
words = [
("python", "A programming language"),
("elephant", "A large mammal"),
("guitar", "A musical instrument"),
("pencil", "Used for writing"),
("planet", "Orbits a star"),
# Drawing steps order: head, body, right arm, left arm, right leg, left leg
MAX_MISSES = 6
class HangmanApp:
def __init__(self, root):
[Link] = root
[Link]("Hangman Game")
[Link]("400x550")
[Link](bg="lightblue")
self.title_label = [Link](root, text="HANGMAN", font=("Helvetica", 24, "bold"),
bg="lightblue")
self.title_label.pack(pady=20)
self.start_button = [Link](root, text="Start", font=("Helvetica", 14),
command=self.show_instructions)
self.start_button.pack()
[Link] = [Link](root, width=300, height=250, bg="white")
self.hint_label = [Link](root, text="", font=("Helvetica", 12), bg="lightblue")
self.blank_label = [Link](root, text="", font=("Helvetica", 20), bg="lightblue")
self.guess_entry = [Link]([Link], font=("Helvetica", 14), justify="center")
self.submit_button = [Link]([Link], text="Guess", command=self.check_guess)
def show_instructions(self):
instructions = (
"Welcome to Hangman!\n\n"
"- You have 6 chances to guess wrong.\n"
"- A hint will be provided.\n"
"- You must guess one letter at a time.\n"
"- Each wrong guess draws one body part.\n"
proceed = [Link]("Instructions", instructions + "\nDo you want to
proceed?")
if proceed:
self.start_button.pack_forget()
self.start_game()
def start_game(self):
[Link] = 0
self.correct_letters = []
self.secret_word, [Link] = [Link](words)
[Link]("all")
[Link](pady=10)
# Draw gallows
[Link].create_line(50, 230, 200, 230, width=3) # Base
[Link].create_line(100, 230, 100, 50, width=3) # Pole
[Link].create_line(100, 50, 180, 50, width=3) # Top bar
[Link].create_line(180, 50, 180, 80, width=3) # Rope
self.hint_label.pack(pady=5)
self.blank_label.pack(pady=5)
self.guess_entry.pack(pady=10)
self.submit_button.pack()
self.display_game()
def display_game(self):
self.hint_label.config(text=f"Hint: {[Link]}")
display = [letter if letter in self.correct_letters else "_" for letter in self.secret_word]
self.blank_label.config(text=" ".join(display))
self.guess_entry.focus()
def draw_body_part(self, part):
# Draw parts based on wrong guess count
if part == 1: # Head
[Link].create_oval(160, 80, 200, 120, width=2)
elif part == 2: # Body
[Link].create_line(180, 120, 180, 170, width=2)
elif part == 3: # Right arm
[Link].create_line(180, 130, 200, 150, width=2)
elif part == 4: # Left arm
[Link].create_line(180, 130, 160, 150, width=2)
elif part == 5: # Right leg
[Link].create_line(180, 170, 200, 200, width=2)
elif part == 6: # Left leg
[Link].create_line(180, 170, 160, 200, width=2)
def check_guess(self):
guess = self.guess_entry.get().lower()
self.guess_entry.delete(0, [Link])
if len(guess) != 1 or not [Link]():
[Link]("Invalid", "Please enter a single letter.")
return
if guess in self.correct_letters:
[Link]("Oops", "You already guessed that letter.")
return
if guess in self.secret_word:
self.correct_letters.append(guess)
else:
[Link] += 1
self.draw_body_part([Link])
if [Link] >= MAX_MISSES:
self.end_game(False)
elif all(letter in self.correct_letters for letter in self.secret_word):
self.end_game(True)
else:
self.display_game()
def end_game(self, won):
result_text = "You Win! " if won else f"You Lost! The word was '{self.secret_word}'"
self.guess_entry.pack_forget()
self.submit_button.pack_forget()
play_again = [Link]("Game Over", result_text + "\nDo you want to play
again?")
if play_again:
self.start_game()
else:
[Link]()
# Run the app
root = [Link]()
app = HangmanApp(root)
[Link]()
.
CHAPTER 6-SYSTEM TESTING
The program was tested with different inputs and workflows.
Test 1: Guessing the word with few wrong guesses
Test 2: Guessing all the words wrong.
Test 3: Guessing the word with no wrong guess.
CHAPTER 7-OUTPUT SCREENS
Fig I
FIG II
FIG III
CHAPTER 8-CONCLUSION
The Hangman game developed using Python and Tkinter provides an engaging way to understand
the fundamentals of GUI programming and event-driven design. The project integrates core
Python concepts such as control structures, functions, string manipulation, and graphical interface
handling.
Key outcomes achieved through this project include an interactive word-guessing game with
dynamic hint display, graphical representation of game status using canvas, and user-friendly
message dialogs to guide gameplay. Some of the key learning from the development process are:
• Practical implementation of Tkinter widgets, canvas drawings, and event handling
• Designing user interfaces with buttons, labels, entry fields, and pop-up dialogs
• Managing game logic through functions and class-based structure
• Handling input validation and user feedback for better interaction
• Applying object-oriented programming to structure a modular and maintainable codebase
This project serves as a foundation for more complex applications involving GUI design and can
be further enhanced with features like custom word lists, difficulty levels, timer-based gameplay,
and score tracking to make it more interactive and challenging.
CHAPTER 9-FUTURE ENHANCEMENT
Some future enhancement ideas for the hangman game:
1. Mobile App:
The game can be extended to mobile platforms like Android and iOS using frameworks such
as Kivy or Flutter. This would allow users to enjoy Hangman on their smartphones or tablets
with touch-based controls.
2. Topic Selection for Word Categories:
The game can be enhanced by allowing players to choose word categories such as animals,
technology, sports, or countries. This adds customization and helps tailor the difficulty and
interest level of the game for different users.
3. Time Limit Per Guess or Game:
A countdown timer can be introduced to increase difficulty and excitement. Players must guess
letters within a time limit, encouraging faster thinking and adding challenge to the game.
4. Score Tracking System:
A scoring mechanism can be implemented based on correct guesses, number of misses, and
time taken. This enables players to compete for high scores, encouraging replayability.
5. Multiplayer Mode:
The game can be made more interactive by allowing two players to compete—one entering a
word and the other guessing, or turn-based guessing with score comparison. This adds a social
and competitive aspect.
6. Multiple Difficulty Levels:
Different game levels such as Easy, Medium, and Hard can be introduced based on word
length, obscurity, or time limits. This accommodates players of varying skill levels and
improves user engagement.
CHAPTER 10-REFERENCES
1. [Link]
2. [Link]
create/?utm_source=flipboard&utm_content=topic%2Fadventuregame
3. [Link]
4. [Link]
5. [Link]
6. [Link]