 # Point Buy Calculator in Tk

Jan 11th, 2018
111
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import tkinter as tk
2. import tkinter.simpledialog as sdg
3. import tkinter.messagebox as mbx
4.
6.     def body(self, master):
8.         self.resizable(False, False)
9.
10.         self.STR = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", label = "Strength", command = self.calculatePoints)
11.         self.DEX = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", label = "Dexterity", command = self.calculatePoints)
12.         self.CON = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", label = "Constitution", command = self.calculatePoints)
13.         self.INT = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", label = "Intelligence", command = self.calculatePoints)
14.         self.WIS = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", label = "Wisdom", command = self.calculatePoints)
15.         self.CHA = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", label = "Charisma", command = self.calculatePoints)
16.
17.         self.currentPoints = tk.IntVar()
18.         self.currentPoints.set(0)
19.
20.         tk.Label(master, textvariable = self.currentPoints).grid(row = 0)
21.
22.         self.STR.grid(row = 1)
23.         self.DEX.grid(row = 2)
24.         self.CON.grid(row = 3)
25.         self.INT.grid(row = 4)
26.         self.WIS.grid(row = 5)
27.         self.CHA.grid(row = 6)
28.
29.
30.
31.     def validate(self):
32.         if self.currentPoints.get() == 27:
33.             return 1
34.         else:
35.             mbx.showerror("Error", "You need to use exactly 27 points to have valid values!")
36.             return 0
37.
38.     def apply(self):
39.         resultString = ""
40.
41.         resultString += str(self.STR.get()) + "|"
42.         resultString += str(self.DEX.get()) + "|"
43.         resultString += str(self.CON.get()) + "|"
44.         resultString += str(self.INT.get()) + "|"
45.         resultString += str(self.WIS.get()) + "|"
46.         resultString += str(self.CHA.get())
47.
48.         self.result = resultString
49.
50.     def calculatePoints(self, changedSlider):
51.         currentScores = []
52.
53.         currentScores.append(self.STR.get())
54.         currentScores.append(self.DEX.get())
55.         currentScores.append(self.CON.get())
56.         currentScores.append(self.INT.get())
57.         currentScores.append(self.WIS.get())
58.         currentScores.append(self.CHA.get())
59.
60.         pointsUsed = 0
61.
62.         for score in currentScores:
63.             if score < 14:
64.                 pointsUsed += score - 8
65.             elif score == 14:
66.                 pointsUsed += 7
67.             elif score == 15:
68.                 pointsUsed += 9
69.
70.         self.currentPoints.set(pointsUsed)
71.
72. base = tk.Tk()