Skip to content

Instantly share code, notes, and snippets.

@mightywombat
Last active May 9, 2018 22:26
Show Gist options
  • Save mightywombat/6e3c55c3c2ecaab3fb9fdfc9e5bd14b9 to your computer and use it in GitHub Desktop.
Save mightywombat/6e3c55c3c2ecaab3fb9fdfc9e5bd14b9 to your computer and use it in GitHub Desktop.
RPG encounter generator.
import Tkinter as tk
import random
import string
root = tk.Tk()
frame = tk.Frame(root)
frame.pack()
# Data pile
about_txt = "This is where the about stuff goes..."
ter_sel = tk.StringVar()
dngr_sel = tk.StringVar()
# Function definition
def crush(word): # Removes all variables from input text for maximum ease of parsing.
word = word.replace(" ", "") # Removes spaces.
word = string.lower(word) # Changes all letters to lowercase.
for c in word:
if c in string.punctuation:
word = word.replace(c, "") # Removes punctuation.
return word
def about_pop():
master = tk.Tk()
about_msg = tk.Message(master, text = about_txt)
about_msg.config( font=( 'times', 12 ))
about_msg.pack()
def close_win():
[]
def random_enc():
[]
def abs_enc():
[]
# Title header
hdr1 = tk.Label(root, text="Encounter Generator")
hdr1.pack(side=tk.LEFT)
# About / exit buttons
about = tk.Button(frame, text="About", command=about_pop)
about.pack(side=tk.LEFT)
quit = tk.Button(frame, text="Exit", command=close_win)
quit.pack(side=tk.RIGHT)
# Spacer
spc1 = tk.Label(root, text=" ")
spc1.pack()
# Section header
hdr2 = tk.Label(root, text="Choose a Terrain")
hdr2.pack()
# Terrain buttons
ter_list = [
"Town",
"Farm",
"Road",
"Plains",
"Hills" ]
for terrain in ter_list:
tk.Radiobutton(root,
text=terrain,
indicatoron = 0,
width = 20,
padx = 20,
#side = LEFT,
variable = ter_list,
value=crush(terrain)).pack(anchor=tk.W)
# Spacer
spc2 = tk.Label(root, text=" ")
spc2.pack()
# Section header
hdr3 = tk.Label(root, text="Choose a Danger Level")
hdr3.pack()
# Danger buttons
dngr_list = [
("Low", 30),
("Normal", 50),
("High", 80) ]
for danger, modifier in enumerate(dngr_list):
tk.Radiobutton(root,
text=danger,
indicatoron = 0,
width = 20,
padx = 20,
#side = LEFT,
#dngr_sel = crush(danger),
dngr_mod = modifier,
value=danger).pack(anchor=tk.W)
print(danger + " " + modifier)
# Generator buttons
random_enc_btn = tk.Button(frame, text="About", command=random_enc)
random_enc_btn.pack(side=tk.LEFT)
abs_enc_btn = tk.Button(frame, text="Exit", command=abs_enc)
abs_enc_btn.pack(side=tk.RIGHT)
root.mainloop()
@mightywombat
Copy link
Author

Loading slowly.
Needs a solution to "index out of range" error caused by applying dngr_mod to rolls.
Need to populate quantities, encounter tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment