In this tutorial, we’ll create a Random Story Title Generator using Python’s tkinter library. By the end, you’ll have a desktop app that can generate epic fantasy or modern thriller titles, copy them to the clipboard, and display them in a styled GUI.
Step 1: Set up your environment
Make sure you have Python installed (Python 3.7+ recommended). tkinter comes built-in with Python, so no extra installation is needed.
Create a new Python file:
touch random_story_title.py
Step 2: Import required modules
We’ll need a few built-in modules:
import sys
import os
import tkinter as tk
from tkinter import messagebox
import random
Explanation:
tkinter – For building the GUI.
messagebox – To show popups (like “Copied!” messages).
random – To randomly pick words for story titles.
sys & os – Standard modules for system operations (not heavily used here but can help in extensions).
Step 3: Define app colors and fonts
We’ll define a theme for our app so it looks modern and consistent.
# =========================
# THEME
# =========================
APP_BG = "#121212" # Dark background for main window
PANEL_BG = "#1F1F1F" # Darker panels
BTN_BG = "#2C2C2C" # Button background
ACCENT = "#FF6F61" # Accent color for highlights
TEXT_CLR = "#E0E0E0" # Primary text color
SUBTEXT_CLR = "#AAAAAA" # Secondary text color
INPUT_BG = "#333333" # Input box background
INPUT_FG = "#FFFFFF" # Input box text color
FONT = ("Segoe UI", 11)
This is optional, but defining colors upfront makes it easy to tweak the look later.
Step 4: Create the main app class
We’ll wrap the app in a Python class for better structure:
class RandomStoryTitleApp:
def __init__(self, root):
self.root = root
root.title("MateTools – Random Story Title Generator")
root.geometry("1000x580")
root.configure(bg=APP_BG)
root.resizable(False, False)
Explanation:
root is the main window.
geometry sets the window size.
resizable(False, False) disables resizing.
Step 5: Create the left panel
The left panel will contain app title, description, style selector, and buttons.
left = tk.Frame(root, bg=PANEL_BG, width=420)
left.pack(side="left", fill="y")
# Header
header = tk.Frame(left, bg=PANEL_BG)
header.pack(fill="x", padx=16, pady=(18, 10))
tk.Label(
header,
text="MateTools",
bg=PANEL_BG,
fg=ACCENT,
font=("Segoe UI", 20, "bold")
).pack(side="left")
# Subtitle
tk.Label(
left,
text="Random Story Title Generator",
bg=PANEL_BG,
fg=TEXT_CLR,
font=("Segoe UI", 14, "bold")
).pack(anchor="w", padx=16, pady=(0, 2))
Explanation:
Frame is a container for other widgets.
Label displays text.
pack() positions the widgets inside the frame.
Step 6: Add a style selector
Users can choose between Epic Fantasy and Modern Thriller:
tk.Label(left, text="Select Style:", bg=PANEL_BG, fg=TEXT_CLR, font=FONT).pack(anchor="w", padx=16, pady=(0,4))
self.style_var = tk.StringVar(value="Epic Fantasy")
style_menu = tk.OptionMenu(left, self.style_var, "Epic Fantasy", "Modern Thriller")
style_menu.config(bg=BTN_BG, fg="white", relief="flat", font=FONT, width=40)
style_menu["menu"].config(bg=PANEL_BG, fg=TEXT_CLR)
style_menu.pack(anchor="w", padx=16, pady=(0,16))
Explanation:
StringVar stores the selected value.
OptionMenu creates a dropdown menu.
We style it to match the dark theme.
Step 7: Add buttons
We’ll add Generate, Copy, and About buttons:
btn_frame = tk.Frame(left, bg=PANEL_BG)
btn_frame.pack(fill="x", padx=16, pady=16)
def make_btn(text, cmd, color=BTN_BG):
return tk.Button(
btn_frame,
text=text,
command=cmd,
bg=color,
fg="white",
font=("Segoe UI", 11, "bold"),
relief="flat",
height=2,
width=20
)
make_btn("Generate Story Title", self.generate_title, ACCENT).pack(side="top", pady=8)
make_btn("Copy Title", self.copy_title, BTN_BG).pack(side="top", pady=8)
make_btn("About", self.show_about, BTN_BG).pack(side="top", pady=20)
Explanation:
command triggers the function when clicked.
make_btn is a helper to avoid repeating code.
pack(side="top") stacks the buttons vertically.
Step 8: Create the right panel
This panel will display the generated title:
right = tk.Frame(root, bg=APP_BG)
right.pack(side="right", fill="both", expand=True)
self.result_card = tk.Frame(right, bg=PANEL_BG)
self.result_card.pack(padx=30, pady=40, fill="both", expand=True)
tk.Label(
self.result_card,
text="Generated Title",
bg=PANEL_BG,
fg=TEXT_CLR,
font=("Segoe UI", 16, "bold")
).pack(pady=(20, 10))
self.title_label = tk.Label(
self.result_card,
text="--",
bg=PANEL_BG,
fg=ACCENT,
font=("Segoe UI", 18, "bold"),
wraplength=500,
justify="center"
)
self.title_label.pack(pady=40)
Step 9: Define word pools
Each style has adjectives, nouns, and actions to build titles:
self.word_pools = {
"Epic Fantasy": {
"adjectives": ["Lost", "Hidden", "Dark", "Silent", "Mysterious"],
"nouns": ["Kingdom", "Forest", "Legacy", "Dragon", "Throne"],
"actions": ["Awakens", "Rises", "Falls", "Returns", "Whispers"]
},
"Modern Thriller": {
"adjectives": ["Cold", "Silent", "Deadly", "Hidden", "Dark"],
"nouns": ["File", "Case", "Witness", "City", "Agent"],
"actions": ["Hunts", "Flees", "Exposes", "Catches", "Chases"]
}
}
For brevity, we’re using smaller lists here. You can expand them later.
Step 10: Create title generation logic
def generate_title(self):
style = self.style_var.get()
pool = self.word_pools[style]
adjectives = random.sample(pool["adjectives"], random.choice([1, 2]))
nouns = random.sample(pool["nouns"], random.choice([1, 2]))
actions = random.sample(pool["actions"], random.choice([1, 2]))
self.current_title = "The " + " ".join(adjectives + nouns + actions)
self.title_label.config(text=self.current_title)
Explanation:
random.sample picks 1–2 words from each list.
join combines them into a title.
self.title_label.config(text=...) updates the GUI.
Step 11: Copy to clipboard
def copy_title(self):
self.root.clipboard_clear()
self.root.clipboard_append(self.current_title)
messagebox.showinfo("Copied", f"'{self.current_title}' copied to clipboard!")
Clears the clipboard, appends the current title, and shows a message.
Step 12: About popup
def show_about(self):
messagebox.showinfo(
"About",
"MateTools – Random Story Title Generator\n\n"
"• Generate epic fantasy or modern thriller titles\n"
"• Copy titles to clipboard\n\n"
"Built by MateTools"
)
Step 13: Run the app
Finally, add the main loop to launch the GUI:
if __name__ == "__main__":
root = tk.Tk()
RandomStoryTitleApp(root)
root.mainloop()
✅ Congratulations! You now have a working Random Story Title Generator with a sleek dark theme.
You can expand it by:
Adding more word lists for other genres.
Making the title format more flexible.
Adding animations or sound effects when a title is generated.

Top comments (0)