0% found this document useful (0 votes)
6 views

Python Coding Haunted House by Widyan

This document is a Python script that creates an interactive text-based adventure game using the Tkinter library. Players navigate through a spooky story by making choices that lead to different paths and endings. The game features various scenarios, including entering an abandoned house or running into a dark forest, with multiple outcomes based on player decisions.

Uploaded by

stu30.wwidyan.kl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Python Coding Haunted House by Widyan

This document is a Python script that creates an interactive text-based adventure game using the Tkinter library. Players navigate through a spooky story by making choices that lead to different paths and endings. The game features various scenarios, including entering an abandoned house or running into a dark forest, with multiple outcomes based on player decisions.

Uploaded by

stu30.wwidyan.kl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

import tkinter as tk

# Initialize the main window


root = tk.Tk()
root.title("Spooky Adventure")
root.geometry("800x600")
root.configure(bg="#1a1a1a") # Darker, slightly warmer black for main background
# Function to start the story
def start_story():
story_label.config(
text="The wind whispers through the trees, sending a chill down your spine. You stand
before an old, abandoned house, "
"its windows shattered and door slightly ajar. A faint glow from within beckons you
forward, but the dark forest "
"behind you feels just as eerie. What will you do?"
)
choice_button_1.config(text="Enter the house", command=path_one)
choice_button_2.config(text="Run into the forest", command=path_two)

# First Path - Entering the House


def path_one():
story_label.config(
text="You step into the house, the air thick with dust and shadows that seem to move in
the dim light. Suddenly, you see "
"an old woman sitting by a flickering candle. She smiles with a knowing look. 'Come
closer,' she says. Do you trust her?"
)
choice_button_1.config(text="Approach her", command=approach_woman)
choice_button_2.config(text="Run back outside", command=start_story)

def approach_woman():
story_label.config(
text="You cautiously approach the old woman. 'Take this candle,' she whispers, 'and
head to the basement. There's a secret "
"down there.' She hands you a worn candle, its flame flickering ominously. Will you
go to the basement or stay with her?"
)
choice_button_1.config(text="Go to the basement", command=basement_path)
choice_button_2.config(text="Stay with the woman", command=stay_with_woman)

def basement_path():
story_label.config(
text="The basement door creaks open, revealing a staircase leading into darkness. You
descend slowly, candlelight barely illuminating "
"the stone walls. At the bottom, you find an ancient chest bound with iron. Do you
open it or go back upstairs?"
)
choice_button_1.config(text="Open the chest", command=open_chest)
choice_button_2.config(text="Go back upstairs", command=start_story)

def open_chest():
story_label.config(
text="Inside the chest, you find a book with strange symbols. As you touch it, whispers
fill the room. The walls shake, and the door "
"slams shut. You feel trapped. Do you open the book or try to escape?"
)
choice_button_1.config(text="Open the book", command=curse_ending)
choice_button_2.config(text="Try to escape", command=trapped_ending)

# Various ending and path functions


def curse_ending():
story_label.config(
text="The book’s pages glow as you read them, and a chill runs down your spine.
Suddenly, you feel your body fade, becoming one "
"with the whispers. You’ve become a ghostly figure in the house. This is the end. Do
you want to start over?"
)
choice_button_1.config(text="Yes", command=start_story)
choice_button_2.config(text="No", command=end_game)

def trapped_ending():
story_label.config(
text="You rush to the door, but it won’t budge. The candle goes out, and darkness
envelops you. Panicked, you realize there’s no escape. "
"This is the end. Do you want to start over?"
)
choice_button_1.config(text="Yes", command=start_story)
choice_button_2.config(text="No", command=end_game)

def stay_with_woman():
story_label.config(
text="You decide to stay with the woman. She hands you a cup of tea, and as you drink,
your surroundings blur. You feel yourself "
"slowly slipping away, fading into the shadows. You’ve joined the spirits in the house.
This is the end. Do you want to start over?"
)
choice_button_1.config(text="Yes", command=start_story)
choice_button_2.config(text="No", command=end_game)

def path_two():
story_label.config(
text="You dash into the forest, branches scratching at your face. The dense trees block
out the moonlight, and soon you find yourself "
"lost. A strange figure appears in the mist. Do you call out to them or hide?"
)
choice_button_1.config(text="Call out", command=call_out)
choice_button_2.config(text="Hide", command=hide)

def call_out():
story_label.config(
text="The figure turns, revealing glowing eyes that pierce through the mist. 'You
shouldn’t be here,' it whispers as it reaches out, "
"pulling you into the darkness. This is the end. Do you want to start over?"
)
choice_button_1.config(text="Yes", command=start_story)
choice_button_2.config(text="No", command=end_game)

def hide():
story_label.config(
text="You hide behind a tree, holding your breath. The figure moves closer, but
suddenly you notice a faint glow in the distance. "
"Do you investigate the glow or stay hidden?"
)
choice_button_1.config(text="Investigate the glow", command=glow_path)
choice_button_2.config(text="Stay hidden", command=hidden_ending)

def glow_path():
story_label.config(
text="Following the glow, you reach a clearing where an ancient stone circle stands. A
spectral figure floats above the stones. "
"'You seek answers,' it says. 'Will you pay the price?' Do you accept its offer or run
away?"
)
choice_button_1.config(text="Accept the offer", command=spectral_ending)
choice_button_2.config(text="Run away", command=run_away)

def spectral_ending():
story_label.config(
text="The figure touches your forehead, filling you with visions of ancient secrets. You
feel yourself becoming one with the forest, "
"bound to its mysteries forever. This is the end. Do you want to start over?"
)
choice_button_1.config(text="Yes", command=start_story)
choice_button_2.config(text="No", command=end_game)

def run_away():
story_label.config(
text="You turn and flee, but the trees seem to close in around you. Lost and exhausted,
you collapse, realizing you’ve been running in circles. "
"This is the end. Do you want to start over?"
)
choice_button_1.config(text="Yes", command=start_story)
choice_button_2.config(text="No", command=end_game)
def hidden_ending():
story_label.config(
text="You remain hidden, but the forest grows eerily silent. The figure disappears, but
you realize you are utterly alone. "
"Forever lost, you wander endlessly. This is the end. Do you want to start over?"
)
choice_button_1.config(text="Yes", command=start_story)
choice_button_2.config(text="No", command=end_game)

def end_game():
root.quit()

# Create the main story label and buttons


story_label = tk.Label(root, text="", wraplength=700, font=("Arial", 14), bg="#1a1a1a",
fg="#d4c9b6")
story_label.pack(pady=20)

choice_button_1 = tk.Button(root, text="", width=20, height=2, bg="#3c3c3c", fg="#d4c9b6",


font=("Arial", 12))
choice_button_1.pack(pady=10)

choice_button_2 = tk.Button(root, text="", width=20, height=2, bg="#3c3c3c", fg="#d4c9b6",


font=("Arial", 12))
choice_button_2.pack(pady=10)

# Start the story


start_story()

# Run the main loop


root.mainloop()

You might also like