Class 12 Cs
Class 12 Cs
HANGMAN GAME
1
KENDRIYA VIDYALAYA EZHIMALA
CERTIFICATE
Certify that the project entitled “ HANGMAN GAME ”
is a project done by
Name: ………………………………
REG no.: ……………………………
During the period of 2025-26 of his/her study in this school under the
guidance of Mr. Shaji.M , PGT computer science in partial fulfilment
of the requirement for the CBSE Senior Secondary Certificate
Submitted for practical examination held on ………………..
2
DECLERATION
I ………………………..…. REG no:………….…. herby declare that
the project entitled “ Hangman Game ” is the result of original work
done by me during the period of study in class XII of computer science,
KENDRIYA VIDHYALA EZHIMALA under the supervision and
guidance of Mr. Shaji.M , PGT Computer Science
Place: Signature:
Date:
3
ACKNOWLEDGEMENT
4
ABSTRACT
This project implements a Hangman word game using Python’s Tkinter
library for CBSE Class 11. Players guess letters to reveal a hidden word
before the hangman drawing is complete. The game features:
5
INDEX
[Link] TITLE PAGE
NO.
1 INTRODUCTION 7
2 SYSTEM ANALYSIS 8
3 SYSTEM CONFIGURATION 9
4 DEVELOPMENT MACHINE 10
5 MODULES USED 13
6 ALGORITHM 14
7 THE CODE 18
9 CONCLUSION 41
10 FURTHER DEVELOPMENT 42
11 SCREEN LAYOUT 43
12 BIBLIOGRAPHY 47
6
INTRODUCTION
The game offers multiple difficulty levels and word categories, allowing
players to customize their experience. A visual hangman drawing
progressively appears with each incorrect guess, while correctly guessed
letters are revealed in the hidden word. The interface displays guessed
letters and remaining attempts to help players strategize.
The simple yet engaging design makes the game accessible to users of
all skill levels while effectively showcasing fundamental programming
principles through practical application.
7
SYSTEM ANALYSIS
Existing System
Traditional Hangman games require physical materials, manual word
selection by players, and lack standardized rules or difficulty levels. The
hand-drawn nature leads to inconsistent visuals and no progress
tracking.
Proposed System
This digital implementation features:
Automation: Random word selection from categorized lists
GUI: Tkinter-based interface with interactive elements
Visuals: Progressive hangman drawing (6 stages)
Gameplay:
-Three difficulty levels
- Attempt counter
-Win/lose detection
Advantages
1. No physical materials required
2. Standardized rules and visuals
3. Adjustable difficulty
4. Built-in progress tracking
8
SYSTEM CONFIGURATION
HARDWARE:
• Intel Core i5-12450H Processor
• 16GB LPDDR5 RAM
• 512GB SSD Storage
• 15.6" FHD (1920×1080) Display
SOFTWARE:
• Windows 11 Home 64-bit
• Python 3.13.5
• PyCharm Community Edition 2023.1
9
DEVELOPMENT MACHINE
Windows 11:
Windows 11 features major changes to the Windows shell influenced by
the cancelled Windows 10X, including a redesigned Start menu, the
replacement of its "live tiles" with a separate "Widgets" panel on the
taskbar, the ability to create tiled sets of windows that can be minimized
and restored from the taskbar as a group, and new gaming technologies
inherited from Xbox Series X and Series S such as Auto HDR and
DirectStorage on compatible hardware. Internet Explorer (IE) has been
replaced by the Chromium-based Microsoft Edge as the default web
browser, like its predecessor, Windows 10, and Microsoft Teams is
integrated into the Windows shell. Microsoft also announced plans to
allow more flexibility in software that can be distributed via the
Microsoft Store and to support Android apps on Windows 11 (including
a partnership with Amazon to make its app store available for the
function).
10
updates. Windows 11 removed support for 32-bit x86 and 32-bit ARM
CPUs and devices that use BIOS firmware.
On May 18, 2021, Head of Windows Servicing and Delivery John Cable
stated that Windows 10X had been cancelled and that Microsoft would
be “accelerating the integration of key foundational 10X technology into
other parts of Windows and products at the company”.
11
Python:
Python is a high-level, general-purpose programming language. Its
design philosophy emphasizes code readability with the use of
significant indentation.
12
MODULES USED
1. tkinter: This is the core module used for creating the main
Graphical User Interface (GUI), managing windows,
frames, labels, and the drawing canvas.
13
ALGORITHM
The game follows this structured logic flow:
14
2. Frame Controller Logic:
o State 1 (Difficulty Screen): Render branding elements
(Title, Subtitle, Emoji) and difficulty selection triggers.
o State 2 (Category Screen): Programmatically generate
buttons based on the dictionary keys of the selected
difficulty.
o State 3 (Active Gameplay): Execute a split-pane layout
using [Link] objects.
15
o State Modification:
Mismatch: If the guess is incorrect, decrement
chances_left, increment hangman_stage, and trigger
flash_canvas_red() for haptic-style visual feedback.
Canvas Rendering: Update the vector graphics on
the Canvas based on the new hangman_stage index.
16
o Use grab_set() to lock the main window focus.
o Use attributes("-topmost", True) to ensure the dialog stays
above the fullscreen game.
4. Memory Reclamation (reset_game):
o Wipe the Canvas using .delete("all").
o Clear the guessed_letters list.
o Restore widget states to "normal" and apply focus_set() to
the entry field for immediate replayability.
17
THE CODE
import tkinter as tk
import customtkinter as ctk
from tkinter import messagebox
import random
word_lists = {
"Easy": {
"Animals":
["cat","dog","cow","rat","hen","pig","bat","ant","fox","lion","frog","duck","wolf
","goat"],
"Fruits":
["apple","mango","kiwi","pear","plum","grape","lemon","banana","orange","pap
aya"],
"Countries":
["india","china","japan","france","germany","italy","spain","russia","brazil","can
ada","egypt","mexico"]
},
"Medium": {
"Animals":
["zebra","horse","tiger","sheep","panda","camel","otter","eagle","whale","shark"
,"rabbit","turtle","monkey","donkey","cobra"],
"Fruits":
["cherry","lychee","mulberry","blueberry","strawberry","blackberry","watermelo
n","avocado"],
"Countries":
["greece","turkey","sweden","norway","kenya","thailand","switzerland","poland
","bhutan"]
18
},
"Hard": {
"Animals":
["chimpanzee","hippopotamus","rhinoceros","armadillo","crocodile","platypus",
"orangutan","porcupine","axolotl","aardvark","alligator","salamander","flamingo
","koala","anaconda"],
"Fruits":
["pomegranate","dragonfruit","gooseberry","elderberry","huckleberry","breadfru
it","ackee","salak","longan","rambutan"],
"Countries":
["liechtenstein","seychelles","eswatini","mauritania","brunei","vanuatu","djibout
i","nauru","palau"]
}
}
current_difficulty = ""
current_topic = ""
secret_word = ""
guessed_letters = []
chances_left = 6
hangman_stage = 0
window = [Link]()
[Link]("Hangman Game")
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
19
[Link]('-fullscreen', True)
[Link](bg="#121212")
is_popup_open = False
def draw_hangman():
"""Draws the hangman figure based on current stage (0-6)"""
[Link]("all")
20
canvas.create_line(245, 230, 195, 280, width=4, fill="#dddddd")
if hangman_stage >= 4: # Right arm
canvas.create_line(245, 230, 295, 280, width=4, fill="#dddddd")
if hangman_stage >= 5: # Left leg
canvas.create_line(245, 330, 195, 400, width=4, fill="#dddddd")
if hangman_stage >= 6: # Right leg (game over)
canvas.create_line(245, 330, 295, 400, width=4, fill="#dddddd")
def flash_canvas_red():
"""Visual feedback for wrong guess - flashes canvas red briefly"""
original_color = canvas["bg"]
[Link](bg="#7f1d1d")
[Link](100, lambda: [Link](bg=original_color))
def show_word():
"""
Displays the word with guessed letters shown and unguessed as underscores
Returns the display string without spaces
"""
display = ""
for letter in secret_word:
if letter in guessed_letters:
display += letter + " "
else:
display += "_ "
word_label.config(text=display)
21
return [Link](" ", "")
def update_guessed_display():
"""Updates the label showing all guessed letters"""
guessed_text = ", ".join(sorted(guessed_letters))
guessed_label.config(text=f"Guessed letters: {guessed_text}")
popup = [Link](window)
[Link](title)
[Link](bg="#121212")
[Link]("-topmost", True)
w, h = 400, 200
x = (popup.winfo_screenwidth() // 2) - (w // 2)
y = (popup.winfo_screenheight() // 2) - (h // 2)
[Link](f"{w}x{h}+{x}+{y}")
def close_and_unlock(event=None):
global is_popup_open
22
is_popup_open = False
[Link]()
guess_entry.focus_set()
ok_btn.focus_set()
[Link]("<Return>", close_and_unlock)
[Link](window)
popup.grab_set()
[Link](f"{w}x{h}+{x}+{y}")
[Link](False, False)
23
[Link](window)
popup.grab_set()
[Link](
popup,
text=message,
font=("Arial", 18),
bg="#121212",
fg="white",
wraplength=380,
justify="center"
).pack(pady=30)
def play_again():
[Link]()
reset_game()
def back_home():
[Link]()
show_difficulty_screen()
def exit_game():
24
[Link]()
[Link](
btn_frame,
text="Play Again",
command=play_again,
width=140,
height=40,
fg_color="#3b82f6"
).pack(pady=6)
[Link](
btn_frame,
text="Back to Home",
command=back_home,
width=140,
height=40,
fg_color="#374151"
).pack(pady=6)
[Link](
btn_frame,
text="Exit",
command=exit_game,
width=140,
height=40,
25
fg_color="#7f1d1d"
).pack(pady=6)
def check_game_status():
current = show_word()
def reset_game():
"""Resets the game state for a new round"""
global guessed_letters, chances_left, hangman_stage
guessed_letters = []
26
chances_left = 6
hangman_stage = 0
draw_hangman()
show_word()
update_guessed_display()
chances_label.config(text=f"Chances left: {chances_left}")
guess_entry.config(state="normal")
guess_entry.delete(0, [Link])
guess_entry.focus_set()
def select_word():
"""Randomly selects a word from the chosen difficulty and topic"""
global secret_word
secret_word = [Link](word_lists[current_difficulty][current_topic])
topic_label.config(text=f"Topic: {current_topic} | Difficulty:
{current_difficulty}")
def make_guess(event=None):
global is_popup_open, chances_left, hangman_stage
27
return
guess = guess_entry.get().lower().strip()
guess_entry.delete(0, [Link])
if guess in guessed_letters:
guessed_letters.append(guess)
update_guessed_display()
show_word()
check_game_status()
28
def select_difficulty(difficulty):
"""Called when player selects a difficulty level"""
global current_difficulty
current_difficulty = difficulty
update_category_buttons()
show_category_screen()
def select_topic(topic):
"""Called when player selects a category/topic"""
global current_topic
current_topic = topic
select_word()
reset_game()
show_game_screen()
def update_category_buttons():
"""Dynamically creates category buttons based on selected difficulty"""
[Link](category_buttons_frame,
text=f"Select Category ({current_difficulty})",
font=("Arial", normal_font),
bg="#121212",
fg="#dddddd").pack(pady=40)
29
for topic in word_lists[current_difficulty]:
btn = [Link](
category_buttons_frame,
text=topic,
command=lambda t=topic: select_topic(t),
font=("Arial", int(normal_font * 1.2), "bold"),
width=350,
height=70,
corner_radius=200,
fg_color="#3b82f6",
hover_color="#2563eb",
text_color="white"
)
[Link](pady=20)
back_btn = [Link](
category_buttons_frame,
text="← Back to Difficulties",
command=show_difficulty_screen,
font=("Arial", 16),
width=200,
height=40,
corner_radius=100,
fg_color="#374151",
hover_color="#4b5563",
30
text_color="white"
)
back_btn.pack(pady=30)
def show_difficulty_screen():
"""Shows the difficulty selection screen"""
difficulty_frame.pack()
category_frame.pack_forget()
game_frame.pack_forget()
def show_category_screen():
"""Shows the category selection screen"""
difficulty_frame.pack_forget()
category_frame.pack()
game_frame.pack_forget()
def show_game_screen():
"""Shows the main game screen"""
difficulty_frame.pack_forget()
category_frame.pack_forget()
game_frame.pack(fill="both", expand=True)
31
[Link](title_container,
text="H A N G M A N",
font=("Arial Black", 70, "bold"),
bg="#121212",
fg="#3b82f6").pack()
[Link](title_container,
text="━━━━━ The Classic Word Game ━━━━━",
font=("Arial", 18),
bg="#121212",
fg="#6b7280").pack(pady=(10, 0))
[Link](title_container,
text="🎮",
font=("Arial", 40),
bg="#121212",
fg="#6b7280").pack(pady=(5, 0))
[Link](difficulty_frame,
text="Choose Difficulty:",
font=("Arial", normal_font),
bg="#121212",
fg="#dddddd").pack(pady=40)
32
btn = [Link](
difficulty_frame,
text=difficulty,
command=lambda d=difficulty: select_difficulty(d),
font=("Arial", int(normal_font * 1.2), "bold"),
width=350,
height=70,
corner_radius=200,
fg_color="#3b82f6",
hover_color="#2563eb",
text_color="white"
)
[Link](pady=20)
[Link](cat_title_container,
text="H A N G M A N",
font=("Arial Black", 70, "bold"),
bg="#121212",
fg="#3b82f6").pack()
[Link](cat_title_container,
33
text="━━━━━ The Classic Word Game ━━━━━",
font=("Arial", 18),
bg="#121212",
fg="#6b7280").pack(pady=(10, 0))
[Link](cat_title_container,
text="🎮",
font=("Arial", 40),
bg="#121212",
fg="#6b7280").pack(pady=(5, 0))
topic_label = [Link](top_frame,
text="",
font=("Arial", 36, "bold"),
bg="#1e1e1e",
fg="#dddddd")
34
topic_label.pack()
back_button = [Link](
top_frame,
text="← Back to Categories",
command=show_category_screen,
font=("Arial", 16),
width=200,
height=40,
corner_radius=100,
fg_color="#374151",
hover_color="#4b5563",
text_color="white"
)
back_button.place(x=20, y=20)
canvas = [Link](main_game_area,
bg="#121212",
width=350,
height=500,
highlightthickness=2,
highlightbackground="#444444")
[Link](side="left", padx=40, pady=10)
35
right_panel = [Link](main_game_area, bg="#1e1e1e")
right_panel.pack(side="left", fill="both", expand=True, padx=40)
[Link](guess_frame,
text="Enter a letter:",
font=("Arial", 24),
bg="#1e1e1e",
fg="#dddddd").pack(side="left", padx=10)
guess_entry = [Link](
guess_frame,
width=3,
font=("Arial", 36),
justify="center",
bg="#2e2e2e",
fg="white",
insertbackground="white",
highlightthickness=1,
highlightbackground="#444444",
relief="flat"
)
guess_entry.pack(side="left", padx=15)
36
guess_entry.bind("<Return>", lambda event: make_guess())
guess_btn = [Link](
guess_frame,
text="Guess",
command=make_guess,
font=("Arial", 18, "bold"),
width=120,
height=40,
corner_radius=200,
fg_color="#3b82f6",
hover_color="#2563eb",
text_color="white"
)
guess_btn.pack(side="left", padx=15)
word_label = [Link](right_panel,
font=("Courier", 56, "bold"),
bg="#1e1e1e",
fg="white")
word_label.pack(pady=40)
chances_label = [Link](info_frame,
37
text="Chances left: 6",
font=("Arial", 24),
bg="#1e1e1e",
fg="white")
chances_label.pack(pady=10)
guessed_label = [Link](info_frame,
text="Guessed letters: ",
font=("Arial", 20),
bg="#1e1e1e",
fg="white")
guessed_label.pack(pady=10)
show_difficulty_screen()
[Link]()
38
HOW TO RUN THIS CODE
python --version
Download: If not installed, download the latest version from
Bash
pip install customtkinter
3. Script Preparation
1. File Saving: Copy the source code and save it into a file named
hangman_game.py.
2. Resource Integrity: Ensure the file is saved with UTF-8
encoding to support the emojis used in the UI.
4. Execution Methods
There are two primary ways to launch your project:
39
Method A: Using an Integrated Development Environment (IDE)
Open the file in VS Code, PyCharm, or IDLE.
40
CONCLUSION
41
FURTHER DEVELOPMENT
Sound Effects: Adding background music and sound effects for correct
and wrong guesses would make the game more interactive and
engaging.
Hints: A limited hint feature (e.g., revealing one letter) can help players
when they are stuck, especially on harder levels.
42
SCREEN LAYOUT
[Link] Screen:
The screen where users can select the difficulty level of the game.
[Link] Screen:
The screen where users can the select the category of the word for
the game.
43
[Link] Screen:
This screen is where the user can play the game. Users can guess the
letters here. If the guessed letter is not in the provided secret word a
part of the hangman appears.
4. Wrong Guess:
When the user guesses the wrong letter a part of the hangman
appears.
44
[Link] Guess:
When the user guesses the correct letter , the letter will appear in its
respective position.
[Link] Lose:
If the hangman gets fully drawn or the Chances left becomes 0 the
user loses the game.
45
6. Game Win:
If the user guesses all the words correctly, the word will get
revealed and he wins the game.
46
BIBLIOGRAPHY
4. GeeksforGeeks
[Link]
(Helped with learning GUI elements and event handling)
47