interactive story game in python using gui

introduction
The Interactive story game in python using gUI is a visually rich, dynamic, and engaging GUI-based adventure built using Python’s Tkinter module, designed specifically to run inside Jupyter Notebook. It blends storytelling with interactivity, allowing players to experience branching narratives where every choice leads to a different consequence or ending.
This version of the game upgrades the classic “choose your own adventure” format with aesthetic improvements—including dark-themed GUI, custom fonts, emojis, stylized buttons, and smooth navigation. By combining simple game logic with a well-structured GUI, it becomes both a learning tool for Python/Tkinter and an enjoyable storytelling experience.
What Makes It Special?
Unlike plain text games or console-based choices, this GUI version:
Uses intuitive buttons for user choices instead of typing input.
Displays bold story text inside a bordered frame that mimics fantasy scrolls.
Enhances visual appeal using emojis, color schemes, and modern fonts.
Offers a modular story engine, making it easy to expand and modify.
Educational Value
This project is perfect for:
Python beginners learning GUI development.
Understanding event-driven programming via button callbacks.
Practicing data structure usage (dict-based story trees).
Exploring narrative logic, branching, and recursion concepts.
Technical Features:
Feature | Description |
---|---|
Tkinter GUI | Easy-to-use buttons, frames, and labels to build a smooth layout |
Scene Dictionary | Each scene is mapped with a story and choices in a centralized data structure |
Dynamic Buttons | Buttons update automatically based on the story tree |
Emoji Styling | Makes the experience more expressive and modern |
Dark Theme UI | Uses dark backgrounds and soft foreground colors for better readability |
Player Experience
The game begins with a scene description and two choices. Clicking one advances the story to a new scenario based on your decision. Some paths lead to victory, others to failure, and many to unexpected twists. Players can make Interactive story game in python using gUI:
Restart the game anytime
Exit directly from the interface
Replay to discover all endings
Customization Potential
The story system is fully extensible:
Add as many scenes and choices as you like.
Use conditions or variables to create personalized paths.
Include images, sounds, or input fields for deeper interaction.
This project offers a complete storytelling framework with:
A clean visual design
Interactive gameplay without complex logic
A strong foundation to build larger games, learning apps, or simulations
steps to create interactive story game
Step 1: Open Jupyter Notebook
Launch Jupyter Notebook from Anaconda, VS Code, or command line.
Create a new notebook file:
interactive_story_game.ipynb
.
Step 2: Import Required Library
import tkinter as tk
Only
tkinter
is needed for GUI. It is built-in in standard Python (no extra installation required).
Step 3: Set Up the Story Engine (Dictionary)
Define a Python dictionary that holds:
The story text for each scene.
The available choices and the next scene for each choice.
self.story = {
"start": {
"text": "You wake up in a magical forest...",
"choices": [("Enter the blue portal", "ice_world"), ("Enter the red portal", "fire_world")]
},
...
}
Step 4: Create the GUI Class Structure
Use a class (FancyStoryGameApp
) to wrap your game logic and GUI setup.
Inside the __init__()
method:
Create and style the main window.
Add a title label (with font and color).
Add a story display label (to show the current scene).
Create two buttons for choices.
Link the buttons to the function
make_choice()
.
Step 5: Create update_story()
Method
This function:
Reads the current scene from
self.story
.Updates the story label text.
Updates the button text and destination state dynamically.
def update_story(self):
...
Step 6: Create make_choice()
Method
Triggered when a button is clicked:
Gets the
next_state
stored in the button.Updates the current scene.
Calls
update_story()
again.
def make_choice(self, i):
...
Step 7: Initialize and Run the App
Outside the class:
root = tk.Tk()
app = FancyStoryGameApp(root)
root.mainloop()
This starts the GUI loop inside Jupyter and runs the game window.
Optional (For Jupyter Compatibility)
If using Jupyter:
Run the entire code in one cell.
Minimize use of
print()
; rely on GUI output.Use
%gui tk
magic if issues occur with display.
Bonus Step: Style the GUI
Enhance your game visually:
Use emojis for fun.
Use
font=()
,bg=
,fg=
,activebackground=
,relief=
to make your game stylish and interactive.
Example:
font=("Verdana", 12, "bold"), bg="#7bed9f", fg="#2f3542"
code explanation
1.Import Tkinter
import tkinter as tk
tkinter
: Built-in Python GUI library to create windows, labels, buttons, and user interactions.
2.Define the Story Game Class
class FancyStoryGameApp:
Creates an object-oriented structure to hold all game logic and UI setup inside one class.
3.Constructor: __init__(self, root)
def __init__(self, root):
Initializes the GUI window and all elements.
4.Window Setup
root.title(" The Epic Choice Adventure")
root.geometry("750x500")
root.configure(bg="#1e272e")
Sets the game window title, size, and background color using a dark fantasy theme.
5.Title Label
self.title_label = tk.Label(...)
Displays a bold heading with emojis and the Papyrus font for a fantasy feel.
6.Main Story Text Box
self.story_label = tk.Label(...)
Shows the current story paragraph.
Styled with
wraplength
, padding, and a grooved border to simulate a parchment.Uses Georgia font for elegant readability.
7.Buttons for Choices
self.button_frame = tk.Frame(...)
self.buttons = []
A horizontal frame holds 2 buttons side by side.
Buttons are created in a loop:
Width = 30
Font = bold
bg
,fg
,activebackground
,activeforeground
for hover feelcommand=lambda i=i: self.make_choice(i)
links the buttons to the choice handler.
8.Story Structure (self.story
)
self.story = {
"start": {
"text": " You awaken in a magical forest...",
"choices": [(" Enter Blue Portal", "ice_world"), (" Enter Red Portal", "fire_world")]
},
...
}
Each key is a scene ID (like "start"
or "ice_world"
).
Each scene has:
text
: Paragraph to display.choices
: List of(Button Text, Next Scene)
pairs.
This makes the story modular and expandable.
9.Start State + Story Update
self.current_state = "start"
self.update_story()
Initializes the game at the
"start"
scene and callsupdate_story()
to load it.
update_story()
Method
def update_story(self):
Loads the current scene’s paragraph and updates the 2 buttons’ text and destination scene.
Uses:
self.story_label.config(text=state["text"]) self.buttons[i].config(text=choice_text) self.buttons[i].state = next_state
make_choice()
Method
def make_choice(self, i):
When a player clicks a button:
It reads the
state
value stored in that button.If it’s
"exit"
, the game closes.Else, updates the
current_state
and shows the new scene.
Launch the Game
root = tk.Tk()
app = FancyStoryGameApp(root)
root.mainloop()
Initializes and launches the Tkinter GUI game.
Summary of Components
Part | Purpose |
---|---|
story dict | Stores story scenes and choices |
story_label | Displays story text |
buttons | Lets player choose between paths |
make_choice() | Handles button clicks |
update_story() |
source code
import tkinter as tk
class FancyStoryGameApp:
def __init__(self, root):
self.root = root
root.title(" The Epic Choice Adventure")
root.geometry("750x500")
root.configure(bg="#1e272e")
# Title
self.title_label = tk.Label(
root, text=" Choose Your Path ",
font=("Papyrus", 22, "bold"), fg="#f7f1e3", bg="#1e272e"
)
self.title_label.pack(pady=10)
# Story Display
self.story_label = tk.Label(
root, text="", wraplength=700, justify="left",
font=("Georgia", 14), fg="#f5f6fa", bg="#2f3640", padx=20, pady=20, relief="groove", bd=4
)
self.story_label.pack(pady=10, fill="x", padx=20)
# Choice Buttons
self.button_frame = tk.Frame(root, bg="#1e272e")
self.button_frame.pack(pady=10)
self.buttons = []
for i in range(2):
btn = tk.Button(
self.button_frame, text="", width=30, height=2,
font=("Verdana", 12, "bold"), bg="#7bed9f", fg="#2f3542",
activebackground="#2ed573", activeforeground="white",
command=lambda i=i: self.make_choice(i)
)
btn.grid(row=0, column=i, padx=20, pady=10)
self.buttons.append(btn)
# Story Data
self.story = {
"start": {
"text": " You awaken in a magical forest with glowing trees.\nTwo shimmering portals appear. Do you enter the blue one or the red one?",
"choices": [(" Enter Blue Portal", "ice_world"), (" Enter Red Portal", "fire_world")]
},
"ice_world": {
"text": " You step into a frozen realm. A frost dragon approaches!\nDo you cast a freezing spell or run away?",
"choices": [(" Cast Freeze Spell", "freeze"), ("Run Back", "start")]
},
"freeze": {
"text": "💥 The spell stuns the dragon! You find a crystal sword and teleport home. You win!",
"choices": [(" Play Again", "start"), (" Exit Game", "exit")]
},
"fire_world": {
"text": " You enter a lava-filled cave. A fire phoenix blocks your path!\nDo you throw a water potion or hide behind a rock?",
"choices": [(" Throw Water Potion", "splash"), (" Hide Behind Rock", "hide")]
},
"splash": {
"text": "The potion cools the phoenix, revealing a treasure chest! You found gold. You win!",
"choices": [(" Play Again", "start"), (" Exit Game", "exit")]
},
"hide": {
"text": " You slip and fall into lava while hiding. Game Over.",
"choices": [(" Try Again", "start"), (" Exit Game", "exit")]
}
}
self.current_state = "start"
self.update_story()
def update_story(self):
state = self.story[self.current_state]
self.story_label.config(text=state["text"])
for i, (choice_text, next_state) in enumerate(state["choices"]):
self.buttons[i].config(text=choice_text)
self.buttons[i].state = next_state
def make_choice(self, i):
next_state = self.buttons[i].state
if next_state == "exit":
self.root.destroy()
else:
self.current_state = next_state
self.update_story()
# Run in Jupyter
root = tk.Tk()
app = FancyStoryGameApp(root)
root.mainloop()
output


