Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import tkinter.simpledialog as sdg
- import tkinter.messagebox as mbx
- class pointBuyRoot(sdg.Dialog):
- def body(self, master):
- self.title("New Character: Point-Buy Stats")
- self.resizable(False, False)
- self.STR = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", label = "Strength", command = self.calculatePoints)
- self.DEX = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", label = "Dexterity", command = self.calculatePoints)
- self.CON = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", label = "Constitution", command = self.calculatePoints)
- self.INT = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", label = "Intelligence", command = self.calculatePoints)
- self.WIS = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", label = "Wisdom", command = self.calculatePoints)
- self.CHA = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", label = "Charisma", command = self.calculatePoints)
- self.currentPoints = tk.IntVar()
- self.currentPoints.set(0)
- tk.Label(master, textvariable = self.currentPoints).grid(row = 0)
- self.STR.grid(row = 1)
- self.DEX.grid(row = 2)
- self.CON.grid(row = 3)
- self.INT.grid(row = 4)
- self.WIS.grid(row = 5)
- self.CHA.grid(row = 6)
- def validate(self):
- if self.currentPoints.get() == 27:
- return 1
- else:
- mbx.showerror("Error", "You need to use exactly 27 points to have valid values!")
- return 0
- def apply(self):
- resultString = ""
- resultString += str(self.STR.get()) + "|"
- resultString += str(self.DEX.get()) + "|"
- resultString += str(self.CON.get()) + "|"
- resultString += str(self.INT.get()) + "|"
- resultString += str(self.WIS.get()) + "|"
- resultString += str(self.CHA.get())
- self.result = resultString
- def calculatePoints(self, changedSlider):
- currentScores = []
- currentScores.append(self.STR.get())
- currentScores.append(self.DEX.get())
- currentScores.append(self.CON.get())
- currentScores.append(self.INT.get())
- currentScores.append(self.WIS.get())
- currentScores.append(self.CHA.get())
- pointsUsed = 0
- for score in currentScores:
- if score < 14:
- pointsUsed += score - 8
- elif score == 14:
- pointsUsed += 7
- elif score == 15:
- pointsUsed += 9
- self.currentPoints.set(pointsUsed)
- base = tk.Tk()
- pointBuyRoot(base)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement