cookchar

DnD Character Sheet v1.2.3

Jan 16th, 2018
103
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. import tkinter.font as tkf
  5. import tkinter.tix as tix
  6. import random as rnd
  7. import operator as op
  8. import os
  9.  
  10. #Charlie Cook's Dungeons & Dragons Character Sheet Program
  11. #Begun early June 2017
  12. #Last updated mid January 2018
  13.  
  14. #Gets the DEX, STR, and INT scores to set the Reflex, Fortitude, and Will saving throw scores
  15. #Now accommodates for when Ability Scores are changed between base and racial/class bonus mode
  16. #Scores are indexed as follows: STR=0, DEX=1, CON=2, INT=3, WIS=4, CHA=5
  17. def updtSAVETHRW(regularMode = True, altMS = [], alsBS = []):
  18.     if regularMode:
  19.         savingThrows[0] = mainStats[2] + bonusStats[2]
  20.         savingThrows[1] = mainStats[1] + bonusStats[1]
  21.         savingThrows[2] = mainStats[4] + bonusStats[4]
  22.     else:
  23.         savingThrows[0] = altMS[2] + alsBS[2]
  24.         savingThrows[1] = altMS[1] + alsBS[1]
  25.         savingThrows[2] = altMS[4] + alsBS[4]
  26. #Increments the level of the player and checks to see if 5E players are overleveled
  27. #The level, current XP, and required XP are recorded in the experience list in the afore-noted order
  28. def levelUp():
  29.     showMessage = True
  30.     experience[0] += 1  #Increment the player's level
  31.     if LEVLVar.get():   #If the player is using the 5E brackets
  32.         if experience[0] == 20: #If the player has reached level 20, the maximum allowed in 5E
  33.                 mbx.showinfo("Level Up!", "You have reached the maximum level allowed in 5E! Well played!")
  34.                 experience[2] = 999999  #Theoretically, no 5E player should reach such ridiculous XP
  35.         elif experience[0] > 20:        #If they do, be snide to them because they must be cheating
  36.                 mbx.showinfo("Level Up?", "You really should make a new character by now, 5E isn't meant to work with this much XP. To prevent errors, your current XP will be modulated to a six-digit number.")
  37.                 experience[1] = experience[1] % 999999
  38.                 experience[0] -= 1
  39.                 showMessage = False
  40.         else:   #If the player can still level up in the future, set the required XP to the proper amount
  41.             experience[2] = brackets5E[experience[0]]
  42.     else:   #See prior comment
  43.         experience[2] += 100 + 10 * experience[0]
  44.  
  45.     if showMessage:
  46.         mbx.showinfo("Level Up!","Congratulations!\nYou are now Level " + str(experience[0]))
  47. #Refreshes the information in the Stats frame
  48. #Now accommodates for when Ability Scores are changed between base and racial/class bonus mode
  49. #Scores are indexed as follows: STR=0, DEX=1, CON=2, INT=3, WIS=4, CHA=5
  50. def refrSTAT(regularMode = True, altMS = [], altBS = []):
  51.     LEVLLbl.config(text = "Level: " + str(experience[0]))
  52.     HPLbl.config(text = "HP:" + str(health[0]) + "/" + str(health[1]))
  53.     XPLbl.config(text = "XP:" + str(experience[1]) + "/" + str(experience[2]))
  54.     #The below strings are evaluated to their python list objects via the eval() function.
  55.     #This allows for the block of code that updates the scores to not be written twice.
  56.     #Since a situation like this needs an if-else block, it's only worth it if the main code block
  57.     #Is longer than the lines needed to assign the names of the strings to be eval'd
  58.     if regularMode:
  59.         mainStr = "mainStats"
  60.         bonusStr = "bonusStats"
  61.         updtSAVETHRW()
  62.     else:
  63.         mainStr = "altMS"
  64.         bonusStr = "altBS"
  65.         updtSAVETHRW(False, altMS, altBS)
  66.  
  67.     STRLbl.config(text = "STR: " + str(eval(mainStr)[0]))
  68.     DEXLbl.config(text = "DEX: " + str(eval(mainStr)[1]))
  69.     CONLbl.config(text = "CON: " + str(eval(mainStr)[2]))
  70.     INTLbl.config(text = "INT: " + str(eval(mainStr)[3]))
  71.     WISLbl.config(text = "WIS: " + str(eval(mainStr)[4]))
  72.     CHALbl.config(text = "CHA: " + str(eval(mainStr)[5]))
  73.  
  74.     if bonusStats[0] > 0:
  75.         STRBLbl.config(text = "+" + str(eval(bonusStr)[0]))
  76.     else:
  77.         STRBLbl.config(text = str(eval(bonusStr)[0]))
  78.  
  79.     if bonusStats[1] > 0:
  80.         DEXBLbl.config(text = "+" + str(eval(bonusStr)[1]))
  81.     else:
  82.         DEXBLbl.config(text = str(eval(bonusStr)[1]))
  83.  
  84.     if bonusStats[2] > 0:
  85.         CONBLbl.config(text = "+" + str(eval(bonusStr)[2]))
  86.     else:
  87.         CONBLbl.config(text = str(eval(bonusStr)[2]))
  88.  
  89.     if bonusStats[3] > 0:
  90.         INTBLbl.config(text = "+" + str(eval(bonusStr)[3]))
  91.     else:
  92.         INTBLbl.config(text = str(eval(bonusStr)[3]))
  93.  
  94.     if bonusStats[4] > 0:
  95.         WISBLbl.config(text = "+" + str(eval(bonusStr)[4]))
  96.     else:
  97.         WISBLbl.config(text = str(eval(bonusStr)[4]))
  98.  
  99.     if bonusStats[5] > 0:
  100.         CHABLbl.config(text = "+" + str(eval(bonusStr)[5]))
  101.     else:
  102.         CHABLbl.config(text = str(eval(bonusStr)[5]))
  103.  
  104.     FORTLbl.config(text = "Fortitude: " + str(savingThrows[0]))
  105.     REFLLbl.config(text = "Reflex: " + str(savingThrows[1]))
  106.     WILLLbl.config(text = "Will: " + str(savingThrows[2]))
  107. #Increments the current HP if possible
  108. def HPUp():
  109.     if health[0] < health[1]:   #If the current health is less than the max
  110.         health[0] += 1          #Increment it
  111.         if SKILSCORVar.get():   #See the changeScores() function for more information on this block
  112.             changeScores()
  113.         else:
  114.             refrSTAT()
  115. #Decrements the current HP if possible
  116. def HPDown():
  117.     if health[0] > -10:     #If the player won't die by losing health
  118.         health[0] -= 1      #Decrement it
  119.         if SKILSCORVar.get():   #See the changeScores() function for more information on this block
  120.             changeScores()
  121.         else:
  122.             refrSTAT()
  123. #Increments the current XP and levels up if necessary
  124. def XPUp():
  125.     temp = sdg.askinteger("Add XP", "Enter how many experience points you've earned:")
  126.     if type(temp) == int:
  127.         experience[1] += temp
  128.  
  129.     while experience[1] >= experience[2]:   #While the current XP exceeds the required XP
  130.         levelUp()
  131.         if SKILSCORVar.get():   #See the changeScores() function for more information on this block
  132.             changeScores()
  133.         else:
  134.             refrSTAT()
  135.  
  136.     if SKILSCORVar.get():
  137.         changeScores()
  138.     else:
  139.         refrSTAT()
  140. #Changes the leveling requirements between 5E and the 100 + 10 * Current Level formula and re-levels the player
  141. def ChangeXP():
  142.     if mbx.askokcancel("Warning!", "Changing the level up brackets may make things weird. Is it okay to continue?"):
  143.         if LEVLVar.get():   #Switching to 5E
  144.             experience[0] = 1
  145.             experience[2] = brackets5E[1]
  146.  
  147.         else:               #Switching to C^2's homebrew method
  148.             experience[0] = 1
  149.             experience[2] = 110
  150.  
  151.         while experience[1] >= experience[2]:   #See comment in XPUp()
  152.             levelUp()
  153.             if SKILSCORVar.get():   #See the changeScores() function for more information on this block
  154.                 changeScores()
  155.             else:
  156.                 refrSTAT()
  157.  
  158.         if SKILSCORVar.get():
  159.             changeScores()
  160.         else:
  161.             refrSTAT()
  162.     #The below else condition is present because the checkbox that invokes this function
  163.     #will change regardless of the yes or no in the above message box, thus it must be reset if no is selected
  164.     else:
  165.         LEVLVar.set(not LEVLVar.get())
  166. #Root dialog for editing stats
  167. class editStatRoot(sdg.Dialog):
  168.     def body(self, master):
  169.         self.title("Edit Stats")
  170.         self.resizable(False, False)
  171.         self.choice = tk.IntVar()
  172.         self.choice.set(1)
  173.         tk.Label(master, text = "Choose a stat item to edit:", font = ftNormal).grid(row = 0)
  174.        
  175.         STR = tk.Radiobutton(master, text = "Strength", value = 1, variable = self.choice, cursor = "hand2", font = ftNormal)
  176.         DEX = tk.Radiobutton(master, text = "Dexterity", value = 2, variable = self.choice, cursor = "hand2", font = ftNormal)
  177.         CON = tk.Radiobutton(master, text = "Constitution", value = 3, variable = self.choice, cursor = "hand2", font = ftNormal)
  178.         INT = tk.Radiobutton(master, text = "Intelligence", value = 4, variable = self.choice, cursor = "hand2", font = ftNormal)
  179.         WIS = tk.Radiobutton(master, text = "Wisdom", value = 5, variable = self.choice, cursor = "hand2", font = ftNormal)
  180.         CHA = tk.Radiobutton(master, text = "Charisma", value = 6, variable = self.choice, cursor = "hand2", font = ftNormal)
  181.  
  182.         LEV = tk.Radiobutton(master, text = "Level", value = 7, variable = self.choice, cursor = "hand2", font = ftNormal)
  183.         XP = tk.Radiobutton(master, text = "Experience", value = 8, variable = self.choice, cursor = "hand2", font = ftNormal)
  184.         HPC = tk.Radiobutton(master, text = "Current Health", value = 9, variable = self.choice, cursor = "hand2", font = ftNormal)
  185.         HPM = tk.Radiobutton(master, text = "Maximum Health", value = 10, variable = self.choice, cursor = "hand2", font = ftNormal)
  186.  
  187.         STR.grid(row = 5, sticky = "w")
  188.         DEX.grid(row = 6, sticky = "w")
  189.         CON.grid(row = 7, sticky = "w")
  190.         INT.grid(row = 8, sticky = "w")
  191.         WIS.grid(row = 9, sticky = "w")
  192.         CHA.grid(row = 10, sticky = "w")
  193.  
  194.         LEV.grid(row = 1, sticky = "w")
  195.         XP.grid(row = 2, sticky = "w")
  196.         HPC.grid(row = 3, sticky = "w")
  197.         HPM.grid(row = 4, sticky = "w")
  198.  
  199.     def apply(self):
  200.         self.result = self.choice.get()
  201.  
  202. #Edits attributes, health, level, and XP
  203. def editStat():
  204.     choice = editStatRoot(base).result
  205.  
  206.     if type(choice) == int: #If the user didn't hit Cancel in the root dialog
  207.         if choice < 7#If the user wants to edit an Ability Score
  208.             choices = ["Strength", "Dexterity", "Constitution", "Intelligence", "Wisdom", "Charisma"]
  209.  
  210.             temp = []
  211.             try:
  212.                 temp.append(sdg.askinteger("Edit " + choices[choice - 1], "Enter your new " + choices[choice - 1] + ":"))
  213.                 temp.append((temp[0] - 10) // 2)
  214.             except TypeError:
  215.                 temp = None
  216.  
  217.         elif choice == 7:
  218.             temp = sdg.askinteger("Edit Level", "[Warning! This will change your XP!]\nEnter your new level:", initialvalue = experience[0])
  219.             if type(temp) == int and temp > 0:
  220.                 experience[0] = temp
  221.                 if LEVLVar.get():
  222.                     if experience[0] > 20:
  223.                         mbx.showinfo("Warning!", "When using the 5E level up brackets, you cannot have a level greater than 20. To prevent errors, your entered level will now be modulated to a number from 1 to 20.")
  224.                         experience[0] = experience[0] % 20
  225.  
  226.                     if experience[0] == 20:
  227.                         experience[2] = 999999
  228.                     else:
  229.                         experience[2] = brackets5E[experience[0]]
  230.                     experience[1] = brackets5E[experience[0] - 1]
  231.                 else:
  232.                     experience[2] = 0
  233.                     for i in range(1, experience[0] + 1):
  234.                         experience[2] += 100 + 10 * i
  235.  
  236.                     experience[1] = experience[2] - (100 + 10 * experience[0])
  237.  
  238.             elif type(temp) == int and temp <= 0:
  239.                 mbx.showerror("Error", "You can't have a negative level!")
  240.  
  241.         elif choice == 8:
  242.             temp = sdg.askinteger("Edit Experience", "[Warning! This will change your level!]\nEnter your new current experience points:", initialvalue = experience[1])
  243.             if type(temp) == int and temp >= 0:
  244.                 experience[1] = temp
  245.                 experience[0] = 1
  246.  
  247.                 if LEVLVar.get():
  248.                     experience[2] = 300
  249.                 else:
  250.                     experience[2] = 110
  251.  
  252.                 while experience[1] >= experience[2]:
  253.                     levelUp()
  254.                     if SKILSCORVar.get():
  255.                         changeScores()
  256.                     else:
  257.                         refrSTAT()
  258.             elif type(temp) == int and temp < 0:
  259.                 mbx.showerror("Error", "You can't have negative experience points!")
  260.  
  261.         elif choice == 9:
  262.             temp = health[1] + 1
  263.  
  264.             while temp > health[1]:
  265.                 temp = sdg.askinteger("Edit Health", "Enter your new current health:", initialvalue = health[0])
  266.                 if type(temp) != int:
  267.                     return
  268.                 elif temp > health[1]:
  269.                     mbx.showerror("Error", "You can't overcharge your health!")
  270.  
  271.             if type(temp) == int and temp >= -10:
  272.                 health[0] = temp
  273.             elif type(temp) == int and temp < -10:
  274.                 mbx.showerror("Error", "You can't have your health drop below -10, you'd be dead then!")
  275.  
  276.         elif choice == 10:
  277.             temp = sdg.askinteger("Edit Health", "Enter your new maximum health:", initialvalue = health[1])
  278.             if type(temp) == int and temp > 0:
  279.                 health[1] = temp
  280.                 if health[0] > health[1]:
  281.                     health[0] = health[1]
  282.             elif type(temp) == int and temp <= 0:
  283.                 mbx.showerror("Error", "You can't have a negative maximum health!")
  284.  
  285.         if type(temp) == list:
  286.             if type(temp[0]) == int:
  287.                 mainStats[choice - 1] = temp[0]
  288.  
  289.             if type(temp[1]) == int:
  290.                 bonusStats[choice - 1] = temp[1]
  291.  
  292.         if type(temp) in (int, list):
  293.             if SKILSCORVar.get():
  294.                 changeScores()
  295.             else:
  296.                 refrSTAT()
  297. #Refreshes the information frame
  298. def refrINFO():
  299.     NAMELbl.config(text = info[0])
  300.     CLSSLbl.config(text = "Class: " + info[1])
  301.     DETYLbl.config(text = "Deity: " + info[2])
  302.     RACELbl.config(text = "Race: " + info[3])
  303.     GNDRLbl.config(text = "Gender: " + info[4])
  304.     AYGELbl.config(text = "Age: " + str(info[5]))
  305.     HGHTLbl.config(text = str(info[6]) + " " + info[7])
  306.     WGHTLbl.config(text = str(info[8]) + " " + info[9])
  307.     HAIRLbl.config(text = "Hair: " + info[10])
  308.     EYESLbl.config(text = "Eyes: " + info[11])
  309.     MONYLbl.config(text = str(info[13]) + " " + info[12])
  310. #Changes the amount of money
  311. def changeMoney()#Money is kept as an integer to prevent floating-point-arithmetic errors
  312.     debit = sdg.askinteger("Change Money", "How much money to add/remove?")
  313.     if type(debit) == int:
  314.         info[13] += debit
  315.         refrINFO()
  316. #Root dialog for editing information
  317. class editInfoRoot(sdg.Dialog):
  318.     def body(self, master):
  319.         self.title("Edit Info")
  320.         self.resizable(False, False)
  321.         self.choice = tk.IntVar()
  322.         self.choice.set(1)
  323.         tk.Label(master, text = "Choose an info item to edit:", font = ftNormal).grid(row = 0)
  324.        
  325.         Name = tk.Radiobutton(master, text = "Name", value = 1, variable = self.choice, cursor = "hand2", font = ftNormal)
  326.         Class = tk.Radiobutton(master, text = "Class", value = 2, variable = self.choice, cursor = "hand2", font = ftNormal)
  327.         Deity = tk.Radiobutton(master, text = "Deity", value = 3, variable = self.choice, cursor = "hand2", font = ftNormal)
  328.         Race = tk.Radiobutton(master, text = "Race", value = 4, variable = self.choice, cursor = "hand2", font = ftNormal)
  329.         Gender = tk.Radiobutton(master, text = "Gender", value = 5, variable = self.choice, cursor = "hand2", font = ftNormal)
  330.         Age = tk.Radiobutton(master, text = "Age", value = 6, variable = self.choice, cursor = "hand2", font = ftNormal)
  331.         Height = tk.Radiobutton(master, text = "Height", value = 7, variable = self.choice, cursor = "hand2", font = ftNormal)
  332.         Weight = tk.Radiobutton(master, text = "Weight", value = 8, variable = self.choice, cursor = "hand2", font = ftNormal)
  333.         HairColor = tk.Radiobutton(master, text = "Hair Color", value = 9, variable = self.choice, cursor = "hand2", font = ftNormal)
  334.         EyeColor = tk.Radiobutton(master, text = "Eye Color", value = 10, variable = self.choice, cursor = "hand2", font = ftNormal)
  335.         Currency = tk.Radiobutton(master, text = "Currency", value = 11, variable = self.choice, cursor = "hand2", font = ftNormal)
  336.  
  337.         Name.grid(row = 1, sticky = "w")
  338.         Class.grid(row = 2, sticky = "w")
  339.         Deity.grid(row = 3, sticky = "w")
  340.         Race.grid(row = 4, sticky = "w")
  341.         Gender.grid(row = 5, sticky = "w")
  342.         Age.grid(row = 6, sticky = "w")
  343.         Height.grid(row = 7, sticky = "w")
  344.         Weight.grid(row = 8, sticky = "w")
  345.         HairColor.grid(row = 9, sticky = "w")
  346.         EyeColor.grid(row = 10, sticky = "w")
  347.         Currency.grid(row = 11, sticky = "w")
  348.  
  349.     def apply(self):
  350.         self.result = self.choice.get()
  351. #Dialog for editing height and/or weight
  352. class editWH(sdg.Dialog):
  353.     def __init__(self, master = None, m = 9):
  354.         self.mode = m - 7
  355.         super().__init__(master)
  356.  
  357.     def toggleUnit(self):
  358.         if self.ChangeUnit.get() == 1:
  359.             self.Unit.config(state = "normal")
  360.         else:
  361.             self.Unit.config(state = "disabled")
  362.  
  363.     def body(self, master):
  364.         choices = ["height", "weight"]
  365.         self.title("Edit " + choices[self.mode].title())
  366.         self.resizable(False, False)
  367.         self.ChangeUnit = tk.IntVar()
  368.         self.ChangeUnit.set(0)
  369.         tk.Label(master, text = "Enter your new " + choices[self.mode] + ":", font = ftNormal).grid(row = 0)
  370.  
  371.         self.Value = tk.Entry(master, font = ftNormal)
  372.         self.Unit = tk.Entry(master, font = ftNormal)
  373.  
  374.         if self.mode == 0:
  375.             self.Value.insert(0, info[6])
  376.             self.Unit.insert(0, info[7])
  377.         elif self.mode == 1:
  378.             self.Value.insert(0, info[8])
  379.             self.Unit.insert(0, info[9])
  380.  
  381.         self.Unit.config(state = "disabled")
  382.  
  383.         ChangeUnitChk = tk.Checkbutton(master, text = "Check to change unit", variable = self.ChangeUnit, command = self.toggleUnit, font = ftNormal)
  384.  
  385.         self.Value.grid(row = 1)
  386.         self.Unit.grid(row = 3)
  387.         ChangeUnitChk.grid(row = 2)
  388.  
  389.     def apply(self):
  390.         try:
  391.             self.result = [int(self.Value.get()), self.Unit.get(), self.ChangeUnit.get()]
  392.         except:
  393.             mbx.showerror("Error","Invalid Measurement")
  394.             self.result = []
  395. #Wrapper function (?) for editing information
  396. def editInfo():
  397.     editInfoSelect(editInfoRoot(base).result)
  398.     refrINFO()
  399. #Function for editing information
  400. def editInfoSelect(choice):
  401.     if choice in range(1, 7) or choice in range(9, 12):
  402.         if choice < 8:
  403.             index = choice - 1
  404.         else:
  405.             index = choice + 1
  406.  
  407.         choices = ["", "name", "class", "deity", "race", "gender", "age", "", "", "hair color", "eye color", "currency"]
  408.        
  409.         if choice == 6:
  410.             temp = sdg.askinteger("Edit " + choices[choice].title(), "Enter your new " + choices[choice], initialvalue = info[index])
  411.    
  412.             if type(temp) == int:
  413.                 info[index] = temp
  414.  
  415.         elif choice != 6:
  416.             temp = sdg.askstring("Edit " + choices[choice].title(), "Enter your new " + choices[choice], initialvalue = info[index])
  417.    
  418.             if type(temp) == str:
  419.                 info[index] = temp
  420.  
  421.     elif choice in range(7, 9):
  422.         n = choice
  423.         if n < 8:
  424.             n -= 1
  425.  
  426.         temp = editWH(base, choice).result
  427.  
  428.         if type(temp) == list and len(temp) > 0:
  429.             info[n] = temp[0]
  430.             if temp[2] == 1:
  431.                 info[n + 1] = temp[1]
  432. #Refreshes the inventory frame
  433. def refrINVT():
  434.     INVTTxt.delete(0, INVTTxt.size())
  435.  
  436.     tempWGHT = 0.0
  437.  
  438.     for item in inventory:
  439.  
  440.         tempWGHT += round(item[2] * item[3], 4)
  441.  
  442.         tempStr = ""
  443.         tempStr += item[0][:36]
  444.         if len(item[0]) > 36:
  445.             tempStr += "... "
  446.         else:
  447.             tempStr += (40 - len(item[0])) * " "
  448.  
  449.         tempStr += str(item[2])
  450.         tempStr += (8 - len(str(item[2]))) * " "
  451.         tempStr += str(item[3])
  452.         tempStr += (8 - len(str(item[3]))) * " "
  453.  
  454.         if item[4] != 0 and item[5]:
  455.             tempStr += "d" + str(item[4]) + " x" + str(item[5])
  456.             tempStr += (8 - len("d" + str(item[4]) + " x" + str(item[5]))) * " "
  457.         else:
  458.             tempStr += 8 * " "
  459.        
  460.         if item[7] != 0:
  461.             tempStr += str(item[6]) + "/" + str(item[7])
  462.             tempStr += (8 - len(str(item[6]) + "/" + str(item[7]))) * " "
  463.         else:
  464.             tempStr += 8 * " "
  465.  
  466.         if item[8]:
  467.             tempStr += "Yes"
  468.         else:
  469.             tempStr += "No"
  470.  
  471.         INVTTxt.insert("end", tempStr)
  472.  
  473.     INVTENCMLbl.config(text = "Encumberance: " + str(tempWGHT))
  474. #Creates a new item
  475. def newItem():
  476.     tempItem = []
  477.     tempStr = ""
  478.  
  479.     try:
  480.         while len(tempStr) == 0:
  481.             tempStr = sdg.askstring("New Item", "Enter the new item's name:")
  482.             if len(tempStr) == 0:
  483.                 mbx.showerror("Error", "You must name your item!")
  484.  
  485.         tempItem.append(tempStr)
  486.  
  487.         tempItem.append(sdg.askstring("New Item", "[Optional] Enter the new item's bonus(es) or description:"))
  488.         if None in tempItem:
  489.             return
  490.  
  491.         tempItem.append(sdg.askinteger("New Item", "Enter how many of the new item you have:", initialvalue = 1))
  492.         if None in tempItem:
  493.             return
  494.  
  495.         tempItem.append(sdg.askfloat("New Item", "Enter the weight of the item:", initialvalue = 0.0))
  496.         if None in tempItem:
  497.             return
  498.  
  499.         tempItem.append(sdg.askinteger("New Item", "[Optional] Enter the type of dice the item uses:", initialvalue = 0))
  500.         if None in tempItem:
  501.             return
  502.  
  503.         tempItem.append(sdg.askinteger("New Item", "[Optional] Enter the amount of dice rolls for the item:", initialvalue = 0))
  504.         if None in tempItem:
  505.             return
  506.        
  507.         tempItem.append(sdg.askinteger("New Item", "[Optional] Enter the maximum magical charges the item has:", initialvalue = 0))
  508.         if None in tempItem:
  509.             return
  510.  
  511.         tempInt = tempItem[6] + 1
  512.         while tempInt > tempItem[6]:
  513.             tempInt = sdg.askinteger("New Item", "[Optional] Enter the current magical charges the item has:", initialvalue = 0)
  514.             if tempInt > tempItem[6]:
  515.                 mbx.showerror("Error", "You can't overcharge your item!")
  516.         tempItem.insert(6, tempInt)
  517.                
  518.         tempItem.append(mbx.askyesno("New Item", "Is the item equipped?"))
  519.  
  520.         inventory.append(tempItem)
  521.         refrINVT()
  522.  
  523.     except TypeError:
  524.         pass
  525. #Root dialog for editing items
  526. class editItemRoot(sdg.Dialog):
  527.     def __init__(self, master = None, i = ""):
  528.         self.item = i
  529.         super().__init__(master)
  530.  
  531.     def body(self, master):
  532.         self.title("Edit " + self.item)
  533.         self.resizable(False, False)
  534.         self.choice = tk.IntVar()
  535.         self.choice.set(0)
  536.         tk.Label(master, text = "Choose an item attribute to edit:", font = ftNormal).grid(row = 0)
  537.  
  538.         Name = tk.Radiobutton(master, text = "Name", value = 0, variable = self.choice, cursor = "hand2", font = ftNormal)
  539.         Bonus = tk.Radiobutton(master, text = "Bonus(es)", value = 1, variable = self.choice, cursor = "hand2", font = ftNormal)
  540.         Count = tk.Radiobutton(master, text = "Count", value = 2, variable = self.choice, cursor = "hand2", font = ftNormal)
  541.         Weight = tk.Radiobutton(master, text = "Weight", value = 3, variable = self.choice, cursor = "hand2", font = ftNormal)
  542.         dType = tk.Radiobutton(master, text = "Dice Type", value = 4, variable = self.choice, cursor = "hand2", font = ftNormal)
  543.         dCount = tk.Radiobutton(master, text = "Dice Count", value = 5, variable = self.choice, cursor = "hand2", font = ftNormal)
  544.         Charges = tk.Radiobutton(master, text = "Charges", value = 6, variable = self.choice, cursor = "hand2", font = ftNormal)
  545.         MaxCharges = tk.Radiobutton(master, text = "Max Charges", value = 7, variable = self.choice, cursor = "hand2", font = ftNormal)
  546.         Equipped = tk.Radiobutton(master, text = "Equipped", value = 8, variable = self.choice, cursor = "hand2", font = ftNormal)
  547.  
  548.         Name.grid(row = 1, sticky = "w")
  549.         Bonus.grid(row = 2, sticky = "w")
  550.         Count.grid(row = 3, sticky = "w")
  551.         Weight.grid(row = 4, sticky = "w")
  552.         dType.grid(row = 5, sticky = "w")
  553.         dCount.grid(row = 6, sticky = "w")
  554.         Charges.grid(row = 7, sticky = "w")
  555.         MaxCharges.grid(row = 8, sticky = "w")
  556.         Equipped.grid(row = 9, sticky = "w")
  557.  
  558.     def apply(self):
  559.         self.result = self.choice.get()
  560. #Changes edited item attributes
  561. def editItem():
  562.     try:
  563.         index = INVTTxt.curselection()[0]
  564.         item = inventory[index]
  565.         attr = editItemRoot(base, item[0]).result
  566.  
  567.         if type(attr) == int:
  568.             choices = ["Name", "Bonus(es)", "Count", "Weight", "Dice Type", "Dice Count", "Charges", "Max Charges", ""]
  569.             title = "Edit " + item[0]
  570.             prompt = "Enter the item's new " + choices[attr] + ":"
  571.  
  572.             if attr < 2:
  573.                 temp = sdg.askstring(title, prompt, initialvalue = item[attr])
  574.  
  575.                 if type(temp) == str and len(temp) > 0 and temp != item[attr]:
  576.                     inventory[index][attr] = temp
  577.  
  578.             elif attr < 6 and attr != 3:
  579.                 temp = sdg.askinteger(title, prompt, initialvalue = item[attr])
  580.  
  581.                 if type(temp) == int and temp != item[attr]:
  582.                     inventory[index][attr] = temp
  583.  
  584.             elif attr == 3:
  585.                 temp = sdg.askfloat(title, prompt, initialvalue = item[attr])
  586.  
  587.                 if type(temp) == float and temp != item[attr]:
  588.                     inventory[index][attr] = temp
  589.  
  590.             elif attr == 6:
  591.                 temp = item[7] + 1
  592.                 while type(temp) == int and temp > item[7]:
  593.                     temp = sdg.askinteger(title, prompt, initialvalue = item[attr])
  594.                    
  595.                     if type(temp) == int and temp > item[7]:
  596.                         mbx.showerror("Error", "You can't overcharge your item!")
  597.  
  598.                 if type(temp) == int and temp != item[attr]:
  599.                     inventory[index][attr] = temp
  600.  
  601.             elif attr == 7:
  602.                 temp = sdg.askinteger(title, prompt, initialvalue = item[attr])
  603.  
  604.                 if type(temp) == int and temp != item[attr]:
  605.                     if temp < item[6]:
  606.                         inventory[index][6] = temp
  607.  
  608.                     inventory[index][attr] = temp
  609.  
  610.             else:
  611.                 inventory[index][attr] =  not inventory[index][attr]
  612.  
  613.             refrINVT()
  614.  
  615.     except IndexError:
  616.         mbx.showerror("Error", "No item selected!")
  617. #Shows an item's bonus(es) or description
  618. def inspectItem():
  619.     try:
  620.         if len(inventory[INVTTxt.curselection()[0]][1]) > 0:
  621.             mbx.showinfo("Item: " + inventory[INVTTxt.curselection()[0]][0], "Bonus:\n" + inventory[INVTTxt.curselection()[0]][1])
  622.         else:
  623.             mbx.showinfo("Item: " + inventory[INVTTxt.curselection()[0]][0], "Bonus:\n[None]")
  624.  
  625.     except IndexError:
  626.         mbx.showerror("Error", "No item selected!")
  627. #Deletes an item
  628. def deleteItem():
  629.     try:
  630.         if mbx.askyesno("Delete Item: " + inventory[INVTTxt.curselection()[0]][0], "Are you sure you want to delete this item?"):
  631.             del inventory[INVTTxt.curselection()[0]]
  632.             refrINVT()
  633.  
  634.     except IndexError:
  635.         mbx.showerror("Error", "No item selected!")
  636. #Root dialog for sorting items
  637. class sortItemsRoot(sdg.Dialog):
  638.     def body(self, master):
  639.         self.title("Sort Items")
  640.         self.resizable(False, False)
  641.         self.choice = tk.IntVar()
  642.         self.order = tk.IntVar()
  643.         self.choice.set(0)
  644.         self.order.set(0)
  645.         tk.Label(master, text = "Choose an attribute to sort by:", font = ftNormal).grid(row = 0)
  646.         tk.Label(master, text = "Choose an order to sort by:", font = ftNormal).grid(row = 9)
  647.  
  648.         Name = tk.Radiobutton(master, text = "Name", value = 0, variable = self.choice, cursor = "hand2", font = ftNormal)
  649.         Count = tk.Radiobutton(master, text = "Count", value = 2, variable = self.choice, cursor = "hand2", font = ftNormal)
  650.         Weight = tk.Radiobutton(master, text = "Weight", value = 3, variable = self.choice, cursor = "hand2", font = ftNormal)
  651.         dType = tk.Radiobutton(master, text = "Dice Type", value = 4, variable = self.choice, cursor = "hand2", font = ftNormal)
  652.         dCount = tk.Radiobutton(master, text = "Dice Count", value = 5, variable = self.choice, cursor = "hand2", font = ftNormal)
  653.         Charges = tk.Radiobutton(master, text = "Charges", value = 6, variable = self.choice, cursor = "hand2", font = ftNormal)
  654.         MaxCharges = tk.Radiobutton(master, text = "Max Charges", value = 7, variable = self.choice, cursor = "hand2", font = ftNormal)
  655.         Equipped = tk.Radiobutton(master, text = "Equipped", value = 8, variable = self.choice, cursor = "hand2", font = ftNormal)
  656.         Ascending = tk.Radiobutton(master, text = "Ascending", value = 1, variable = self.order, cursor = "hand2", font = ftNormal)
  657.         Descending = tk.Radiobutton(master, text = "Descending", value = 0, variable = self.order, cursor = "hand2", font = ftNormal)
  658.  
  659.         Name.grid(row = 1, sticky = "w")
  660.         Count.grid(row = 2, sticky = "w")
  661.         Weight.grid(row = 3, sticky = "w")
  662.         dType.grid(row = 4, sticky = "w")
  663.         dCount.grid(row = 5, sticky = "w")
  664.         Charges.grid(row = 6, sticky = "w")
  665.         MaxCharges.grid(row = 7, sticky = "w")
  666.         Equipped.grid(row = 8, sticky = "w")
  667.         Ascending.grid(row = 10, sticky = "w")
  668.         Descending.grid(row = 11, sticky = "w")
  669.  
  670.     def apply(self):
  671.         self.result = [self.choice.get(), self.order.get()]
  672. #Sorts inventory by various attributes
  673. def sortItems():
  674.     choice = sortItemsRoot(base).result
  675.    
  676.     if type(choice) == list:
  677.         if choice[1] == 1:
  678.             order = True
  679.         else:
  680.             order = False
  681.  
  682.         inventory.sort(key = op.itemgetter(choice[0]), reverse = order)
  683.         refrINVT()
  684. #Rolls virtual dice of various types
  685. def rollDice(d):
  686.     def rollDiceWrap(dice = d):
  687.         if dice == 0:
  688.             DICELbl.config(text = "0 | d?")
  689.         elif dice == 2:
  690.             if rnd.randint(0,1):
  691.                 DICELbl.config(text = "Heads | Coin")
  692.             else:
  693.                 DICELbl.config(text = "Tails | Coin")
  694.         elif dice < 100:
  695.             DICELbl.config(text = str(rnd.randint(1, dice)) + " | d" + str(dice))
  696.         else:
  697.             DICELbl.config(text = str(rnd.randint(0, 100)) + " | d%")
  698.     return rollDiceWrap
  699. #Refreshes the skills frame
  700. def refrSKIL():
  701.     SKILTxt.delete(0, SKILTxt.size())
  702.     stats = ["STR", "DEX", "CON", "INT", "WIS", "CHA"]
  703.  
  704.     for sk in skills:
  705.         SKILTxt.insert("end", stats[sk[0]] + "|" + sk[1])
  706. #Dialog for selecting the attribute stat associated with a skill or ability
  707. class skillStat(sdg.Dialog):
  708.     def __init__(self, master = None, m = "", sa = "", i = 0):
  709.         self.mode = m
  710.         self.skab = sa
  711.         self.index = i
  712.         super().__init__(master)
  713.  
  714.     def body(self, master):
  715.         self.resizable(False, False)
  716.         self.stat = tk.IntVar()
  717.  
  718.         if self.skab == "skill":
  719.             if self.mode == "edit":
  720.                 self.title("Edit " + skills[self.index][1])
  721.                 self.stat.set(skills[self.index][0])
  722.  
  723.             elif self.mode == "new":
  724.                 self.title("New Skill")
  725.                 self.stat.set(0)
  726.  
  727.         elif self.skab == "ability":
  728.             if self.mode == "edit":
  729.                 self.title("Edit " + abilities[self.index][1])
  730.                 self.stat.set(abilities[self.index][0])
  731.  
  732.             elif self.mode == "new":
  733.                 self.title("New Ability")
  734.                 self.stat.set(0)
  735.  
  736.  
  737.         PRMPLbl = tk.Label(master, font = ftSmall)
  738.         PRMPLbl.grid(row = 0)
  739.         if self.skab == "skill":
  740.             if self.mode == "edit":
  741.                 PRMPLbl.config(text = "[Optional] Choose a new stat for the skill:")
  742.             elif self.mode == "new":
  743.                 PRMPLbl.config(text = "Choose a stat for the skill:")
  744.         elif self.skab == "ability":
  745.             if self.mode == "edit":
  746.                 PRMPLbl.config(text = "[Optional] Choose a new stat for the ability:")
  747.             elif self.mode == "new":
  748.                 PRMPLbl.config(text = "Choose a stat for the ability:")
  749.  
  750.         STRBtn = tk.Radiobutton(master, text = "Strength", value = 0, variable = self.stat, font = ftNormal)
  751.         DEXBtn = tk.Radiobutton(master, text = "Dexterity", value = 1, variable = self.stat, font = ftNormal)
  752.         CONBtn = tk.Radiobutton(master, text = "Constitution", value = 2, variable = self.stat, font = ftNormal)
  753.         INTBtn = tk.Radiobutton(master, text = "Intelligence", value = 3, variable = self.stat, font = ftNormal)
  754.         WISBtn = tk.Radiobutton(master, text = "Wisdom", value = 4, variable = self.stat, font = ftNormal)
  755.         CHABtn = tk.Radiobutton(master, text = "Charisma", value = 5, variable = self.stat, font = ftNormal)
  756.        
  757.         STRBtn.grid(row = 1, sticky = "w")
  758.         DEXBtn.grid(row = 2, sticky = "w")
  759.         CONBtn.grid(row = 3, sticky = "w")
  760.         INTBtn.grid(row = 4, sticky = "w")
  761.         WISBtn.grid(row = 5, sticky = "w")
  762.         CHABtn.grid(row = 6, sticky = "w")
  763.  
  764.     def apply(self):
  765.         self.result = self.stat.get()
  766. #Creates a new skill
  767. def newSkill():
  768.     tempStr = ""
  769.     while type(tempStr) == str and len(tempStr) < 1:
  770.         tempStr = sdg.askstring("New Skill", "Enter the new skill's name:")
  771.         if type(tempStr) == str and len(tempStr) < 1:
  772.             mbx.showerror("Error", "You must name this skill!")
  773.  
  774.     if type(tempStr) == str:
  775.         tempInt = skillStat(base, "new", "skill").result
  776.         if type(tempInt) == int:
  777.             skills.append([tempInt, tempStr])
  778.             refrSKIL()
  779.             if SKILSCORVar.get():
  780.                 changeScores()
  781. #Edits a skill
  782. def editSkill():
  783.     try:
  784.         index = SKILTxt.curselection()[0]
  785.         sk = skills[index]
  786.         tempStr = sdg.askstring("Edit " + sk[1], "[Optional] Enter the skill's new name:", initialvalue = sk[1])
  787.         if type(tempStr) == str:
  788.             if len(tempStr) > 0 and tempStr != sk[1]:
  789.                 skills[index][1] = tempStr
  790.            
  791.             tempInt = skillStat(base, "edit", "skill", index).result
  792.             if type(tempInt) == int and tempInt != sk[0]:
  793.                 skills[index][0] = tempInt
  794.  
  795.             refrSKIL()
  796.             if SKILSCORVar.get():
  797.                 changeScores()
  798.     except IndexError:
  799.         mbx.showerror("Error", "No skill selected!")
  800. #Deletes a skill
  801. def deleteSkill():
  802.     try:
  803.         if mbx.askyesno("Delete " + skills[SKILTxt.curselection()[0]][1], "Are you sure you want to delete this skill?"):
  804.             del skills[SKILTxt.curselection()[0]]
  805.             refrSKIL()
  806.             if SKILSCORVar.get():
  807.                 changeScores()
  808.  
  809.     except IndexError:
  810.         mbx.showerror("Error", "No skill selected!")
  811. #Dialog for skills and/or abilities
  812. class sortSkillsAbils(sdg.Dialog):
  813.     def __init__(self, master = None, sa = ""):
  814.         self.skab = sa
  815.         super().__init__(master)
  816.  
  817.     def body(self, master):
  818.         if self.skab == "skill":
  819.             self.title("Sort Skills")
  820.         elif self.skab == "ability":
  821.             self.title("Sort Abilities")
  822.         self.resizable(False, False)
  823.         self.choice = tk.IntVar()
  824.         self.order = tk.IntVar()
  825.         self.choice.set(0)
  826.         self.order.set(0)
  827.         tk.Label(master, text = "Choose an attribute to sort by:", font = ftNormal).grid(row = 0)
  828.         tk.Label(master, text = "Choose an order to sort by:", font = ftNormal).grid(row = 3)
  829.  
  830.         Name = tk.Radiobutton(master, text = "Name", value = 1, variable = self.choice, cursor = "hand2", font = ftNormal)
  831.         Stat = tk.Radiobutton(master, text = "Stat", value = 0, variable = self.choice, cursor = "hand2", font = ftNormal)
  832.         Ascending = tk.Radiobutton(master, text = "Ascending", value = 1, variable = self.order, cursor = "hand2", font = ftNormal)
  833.         Descending = tk.Radiobutton(master, text = "Descending", value = 0, variable = self.order, cursor = "hand2", font = ftNormal)
  834.  
  835.         Name.grid(row = 1, sticky = "w")
  836.         Stat.grid(row = 2, sticky = "w")
  837.         Ascending.grid(row = 4, sticky = "w")
  838.         Descending.grid(row = 5, sticky = "w")
  839.  
  840.     def apply(self):
  841.         self.result = [self.choice.get(), self.order.get()]
  842. #Sorts skills by name or attribute stat
  843. def sortSkills():
  844.     choice = sortSkillsAbils(base, "skill").result
  845.  
  846.     if type(choice) == list:
  847.         if choice[1] == 1:
  848.             order = True
  849.         else:
  850.             order = False
  851.  
  852.         skills.sort(key = op.itemgetter(choice[0]), reverse = order)
  853.         refrSKIL()
  854. #Toggles between including racial/class ability score bonuses into the Stats display
  855. def changeScores():
  856.     if SKILSCORVar.get():
  857.         newScores = []
  858.  
  859.         for i in range(len(mainStats)):
  860.             newScores.append(mainStats[i])
  861.        
  862.         for sk in skills:
  863.             if sk[1][0] in "+-":
  864.                 try:
  865.                     if sk[1][0] == '+':
  866.                         newScores[sk[0]] += int(sk[1][1:].split()[0])
  867.                     else:
  868.                         newScores[sk[0]] += int(sk[1][0:].split()[0])
  869.                 except ValueError:
  870.                     pass
  871.  
  872.         newMods = [0, 0, 0, 0, 0, 0]
  873.         for i in range(len(newScores)):
  874.             newMods[i] = (newScores[i] - 10) // 2
  875.  
  876.         refrSTAT(False, newScores, newMods)
  877.     else:
  878.         refrSTAT()
  879. #Shows the information box regarding the above functionality
  880. def showPrefixInfo():
  881.     mbx.showinfo("Skills: Apply Prefixes", "When checked, all skills whose name have a leading +/- character \
  882. followed by an integer then a space will be compiled and added to your base Ability Scores without changing said scores. \
  883. This is useful for adding temporary skill entries to act as buffs from equipment or spells.")
  884. #Refreshes the abilities frame
  885. def refrABIL():
  886.     ABILTxt.delete(0, ABILTxt.size())
  887.     stats = ["STR", "DEX", "CON", "INT", "WIS", "CHA"]
  888.  
  889.     for ab in abilities:
  890.         ABILTxt.insert("end", stats[ab[0]] + "|" + ab[1])
  891. #Creates a new ability
  892. def newAbility():
  893.     tempStrA = ""
  894.     while type(tempStrA) == str and len(tempStrA) < 1:
  895.         tempStrA = sdg.askstring("New Ability", "Enter the new ability's name:")
  896.        
  897.         if type(tempStrA) == str and len(tempStrA) < 1:
  898.             mbx.showerror("Error", "You must name this ability!")
  899.  
  900.     if type(tempStrA) == str:
  901.         tempInt = skillStat(base, "new", "ability").result
  902.        
  903.         if type(tempInt) == int:
  904.             tempStrB = sdg.askstring("New Ability", "Describe the new ability:")
  905.            
  906.             if type(tempStrB) == str:
  907.                 abilities.append([tempInt, tempStrA, tempStrB])
  908.                 refrABIL()
  909. #Edits an ability
  910. def editAbility():
  911.     try:
  912.         index = ABILTxt.curselection()[0]
  913.         ab = abilities[index]
  914.         tempStr = sdg.askstring("Edit " + ab[1], "[Optional] Enter the ability's new name:", initialvalue = ab[1])
  915.         if type(tempStr) == str:
  916.             if len(tempStr) > 0 and tempStr != ab[1]:
  917.                 abilities[index][1] = tempStr
  918.            
  919.             tempInt = skillStat(base, "edit", "ability", index).result
  920.             if type(tempInt) == int:
  921.                 if tempInt != ab[0]:
  922.                     abilities[index][0] = tempInt
  923.  
  924.                 tempStr = sdg.askstring("Edit " + ab[1], "[Optional] Describe the ability again:", initialvalue = ab[2])
  925.                 if type(tempStr) == str and len(tempStr) > 0 and tempStr != ab[2]:
  926.                     abilities[index][2] = tempStr
  927.  
  928.             refrABIL()
  929.     except IndexError:
  930.         mbx.showerror("Error", "No ability selected!")
  931. #Deletes an ability
  932. def deleteAbility():
  933.     try:
  934.         if mbx.askyesno("Delete " + abilities[ABILTxt.curselection()[0]][1], "Are you sure you want to delete this ability?"):
  935.             del abilities[ABILTxt.curselection()[0]]
  936.             refrABIL()
  937.  
  938.     except IndexError:
  939.         mbx.showerror("Error", "No ability selected!")
  940. #Shows an ability's description
  941. def inspectAbility():
  942.     try:
  943.         if len(abilities[ABILTxt.curselection()[0]][2]) > 0:
  944.             mbx.showinfo("Ability: " + abilities[ABILTxt.curselection()[0]][1], "Description:\n" + abilities[ABILTxt.curselection()[0]][2])
  945.         else:
  946.             mbx.showinfo("Ability: " + abilities[ABILTxt.curselection()[0]][1], "Description:\n[None]")
  947.  
  948.     except IndexError:
  949.         mbx.showerror("Error", "No ability selected!")
  950. #Sorts abilities by name or attribute stat
  951. def sortAbilities():
  952.     choice = sortSkillsAbils(base, "ability").result
  953.  
  954.     if type(choice) == list:
  955.         if choice[1] == 1:
  956.             order = True
  957.         else:
  958.             order = False
  959.  
  960.         abilities.sort(key = op.itemgetter(choice[0]), reverse = order)
  961.         refrABIL()
  962. #Prevents the program from exiting on one click
  963. def exitOverride():
  964.     if mbx.askyesno("Warning! Data Loss Possibility Detected!", "Unsaved data will be lost if you quit. Are you sure you want to quit?"):
  965.         base.destroy()
  966. #Dialog for choosing a method to set main stats
  967. class newCharacterStatRoot(sdg.Dialog):
  968.     def body(self, master):
  969.         self.title("New Character: Stats")
  970.         self.resizable(False, False)
  971.         self.choice = tk.IntVar()
  972.         self.choice.set(0)
  973.  
  974.         tk.Label(master, text = "It is now time to set your ability scores / main stats.\nChoose a method below:", font = ftNormal).grid(row = 0)
  975.         PB = tk.Radiobutton(master, text = "5E Point-Buy", value = 0, variable =  self.choice, cursor = "hand2", font = ftNormal)
  976.         DR = tk.Radiobutton(master, text = "Dice Rolls", value = 1, variable =  self.choice, cursor = "hand2", font = ftNormal)
  977.         MAN = tk.Radiobutton(master, text = "Manual Entry", value = 2, variable =  self.choice, cursor = "hand2", font = ftNormal)
  978.  
  979.         PB.grid(row = 1, sticky = "w")
  980.         DR.grid(row = 2, sticky = "w")
  981.         MAN.grid(row = 3, sticky = "w")
  982.  
  983.     def apply(self):
  984.         self.result = self.choice.get()
  985. #Dialog for a point-buy calculator
  986. class pointBuyRoot(sdg.Dialog):
  987.     def body(self, master):
  988.         self.title("New Character: Point-Buy Stats")
  989.         self.resizable(False, False)
  990.  
  991.         self.STR = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", command = self.calculatePoints, font = ftNormal)
  992.         self.DEX = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", command = self.calculatePoints, font = ftNormal)
  993.         self.CON = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", command = self.calculatePoints, font = ftNormal)
  994.         self.INT = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", command = self.calculatePoints, font = ftNormal)
  995.         self.WIS = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", command = self.calculatePoints, font = ftNormal)
  996.         self.CHA = tk.Scale(master, from_ = 8, to = 15, orient = "horizontal", command = self.calculatePoints, font = ftNormal)
  997.  
  998.         self.bSTRVar = tk.IntVar()
  999.         self.bDEXVar = tk.IntVar()
  1000.         self.bCONVar = tk.IntVar()
  1001.         self.bINTVar = tk.IntVar()
  1002.         self.bWISVar = tk.IntVar()
  1003.         self.bCHAVar = tk.IntVar()
  1004.  
  1005.         self.bSTRVar.set(-1)
  1006.         self.bDEXVar.set(-1)
  1007.         self.bCONVar.set(-1)
  1008.         self.bINTVar.set(-1)
  1009.         self.bWISVar.set(-1)
  1010.         self.bCHAVar.set(-1)
  1011.  
  1012.         bSTR = tk.Label(master, textvariable = self.bSTRVar, width = 2, relief = "ridge", font = ftNormal)
  1013.         bDEX = tk.Label(master, textvariable = self.bDEXVar, width = 2, relief = "ridge", font = ftNormal)
  1014.         bCON = tk.Label(master, textvariable = self.bCONVar, width = 2, relief = "ridge", font = ftNormal)
  1015.         bINT = tk.Label(master, textvariable = self.bINTVar, width = 2, relief = "ridge", font = ftNormal)
  1016.         bWIS = tk.Label(master, textvariable = self.bWISVar, width = 2, relief = "ridge", font = ftNormal)
  1017.         bCHA = tk.Label(master, textvariable = self.bCHAVar, width = 2, relief = "ridge", font = ftNormal)
  1018.  
  1019.         bSTR.grid(row = 2, column = 2, sticky = "s")
  1020.         bDEX.grid(row = 3, column = 2, sticky = "s")
  1021.         bCON.grid(row = 4, column = 2, sticky = "s")
  1022.         bINT.grid(row = 5, column = 2, sticky = "s")
  1023.         bWIS.grid(row = 6, column = 2, sticky = "s")
  1024.         bCHA.grid(row = 7, column = 2, sticky = "s")
  1025.  
  1026.         self.currentPoints = tk.IntVar()
  1027.         self.currentPoints.set(0)
  1028.  
  1029.         tk.Label(master, text = "Point Total:", font = ftLarge).grid(row = 0, column = 0, columnspan = 2)
  1030.         tk.Label(master, textvariable = self.currentPoints, relief = "ridge", width = 2, font = ftLarge).grid(row = 0, column = 1, sticky = "e")
  1031.         tk.Label(master, text = "/27", font = ftLarge).grid(row = 0, column = 2)
  1032.         tk.Label(master, text = "Attribute", font = ftSmall).grid(row = 1, column = 0)
  1033.         tk.Label(master, text = "Value", font = ftSmall).grid(row = 1, column = 1)
  1034.         tk.Label(master, text = "Modifier", font = ftSmall).grid(row = 1, column = 2)
  1035.         tk.Label(master, text = "Strength", width = 16, font = ftNormal).grid(row = 2, column = 0, sticky = "s")
  1036.         tk.Label(master, text = "Dexterity", width = 16, font = ftNormal).grid(row = 3, column = 0, sticky = "s")
  1037.         tk.Label(master, text = "Constitution", width = 16, font = ftNormal).grid(row = 4, column = 0, sticky = "s")
  1038.         tk.Label(master, text = "Intelligence", width = 16, font = ftNormal).grid(row = 5, column = 0, sticky = "s")
  1039.         tk.Label(master, text = "Wisdom", width = 16, font = ftNormal).grid(row = 6, column = 0, sticky = "s")
  1040.         tk.Label(master, text = "Charisma", width = 16, font = ftNormal).grid(row = 7, column = 0, sticky = "s")
  1041.  
  1042.         self.STR.grid(row = 2, column = 1)
  1043.         self.DEX.grid(row = 3, column = 1)
  1044.         self.CON.grid(row = 4, column = 1)
  1045.         self.INT.grid(row = 5, column = 1)
  1046.         self.WIS.grid(row = 6, column = 1)
  1047.         self.CHA.grid(row = 7, column = 1)
  1048.  
  1049.     def validate(self):
  1050.         if self.currentPoints.get() == 27 and mbx.askyesno("Confirmation", "Are you sure you want these values for your main stats?"):
  1051.             return 1
  1052.         elif self.currentPoints.get() != 27:
  1053.             mbx.showerror("Error", "You need to have a Point Total of 27 to have valid values!")
  1054.             return 0
  1055.         else:
  1056.             return 0
  1057.  
  1058.     def apply(self):
  1059.         resultString = ""
  1060.  
  1061.         resultString += str(self.STR.get()) + "|"
  1062.         resultString += str(self.DEX.get()) + "|"
  1063.         resultString += str(self.CON.get()) + "|"
  1064.         resultString += str(self.INT.get()) + "|"
  1065.         resultString += str(self.WIS.get()) + "|"
  1066.         resultString += str(self.CHA.get()) + "\n"
  1067.         resultString += str(self.bSTRVar.get()) + "|"
  1068.         resultString += str(self.bDEXVar.get()) + "|"
  1069.         resultString += str(self.bCONVar.get()) + "|"
  1070.         resultString += str(self.bINTVar.get()) + "|"
  1071.         resultString += str(self.bWISVar.get()) + "|"
  1072.         resultString += str(self.bCHAVar.get())
  1073.  
  1074.         self.result = resultString
  1075.  
  1076.     def calculatePoints(self, changedSlider):
  1077.         self.bSTRVar.set((self.STR.get() - 10) // 2)
  1078.         self.bDEXVar.set((self.DEX.get() - 10) // 2)
  1079.         self.bCONVar.set((self.CON.get() - 10) // 2)
  1080.         self.bINTVar.set((self.INT.get() - 10) // 2)
  1081.         self.bWISVar.set((self.WIS.get() - 10) // 2)
  1082.         self.bCHAVar.set((self.CHA.get() - 10) // 2)
  1083.  
  1084.         currentScores = []
  1085.  
  1086.         currentScores.append(self.STR.get())
  1087.         currentScores.append(self.DEX.get())
  1088.         currentScores.append(self.CON.get())
  1089.         currentScores.append(self.INT.get())
  1090.         currentScores.append(self.WIS.get())
  1091.         currentScores.append(self.CHA.get())
  1092.  
  1093.         pointsUsed = 0
  1094.  
  1095.         for score in currentScores:
  1096.             if score < 14:
  1097.                 pointsUsed += score - 8
  1098.             elif score == 14:
  1099.                 pointsUsed += 7
  1100.             elif score == 15:
  1101.                 pointsUsed += 9
  1102.  
  1103.         self.currentPoints.set(pointsUsed)
  1104. #Dialog for a dice-roll stat selector
  1105. class diceRollStatsRoot(sdg.Dialog):
  1106.     def body(self, master):
  1107.         self.title("New Character: Dice Roll Stats")
  1108.         self.resizable(False, False)
  1109.         self.letters = ('A', 'B', 'C', 'D', 'E', 'F')
  1110.         self.stats = ('STR', 'CHA', 'WIS', 'INT', 'CON', 'DEX')
  1111.         self.rolled = False
  1112.         self.rolls = [0, 0, 0, 0, 0, 0]
  1113.         #self.rollsVar = tk.StringVar()
  1114.         #self.rollsVar.set("Press \"Roll\" to begin!")
  1115.  
  1116.         tk.Label(master, text = "You can swap values between attributes below.\nIn the \"six 4d6\" roll mode,\nthe lowest roll of each batch is not counted.", font = ftSmall).grid(row = 0, columnspan = 3)
  1117.  
  1118.         #rollsLbl = tk.Label(master, textvariable = self.rollsVar, width = 36, relief = "ridge", font = ftNormal)
  1119.         #rollsLbl.grid(row = 1, column = 0, columnspan = 2)
  1120.         self.swapOne = tk.Spinbox(master, width = 4, values = self.stats, wrap = True, font = ftNormal)
  1121.         self.swapTwo = tk.Spinbox(master, width = 4, values = self.stats, wrap = True, font = ftNormal)
  1122.         self.rollMode = tk.Spinbox(master, width = 8, values = ("six 1d20", "six 4d6"), wrap = True, font = ftNormal)
  1123.  
  1124.         self.swapOne.grid(row = 1, column = 0)
  1125.         self.swapTwo.grid(row = 1, column = 1)
  1126.         self.rollMode.grid(row = 2, column = 1)
  1127.  
  1128.         tk.Button(master, text = "Swap", command = self.swap, cursor = "hand2", font = ftNormal).grid(row = 1, column = 2)
  1129.         tk.Label(master, text = "Roll Mode", font = ftNormal).grid(row = 2, column = 0)
  1130.         tk.Button(master, text = "Roll", command = self.rollStats, cursor = "hand2", font = ftNormal).grid(row = 2, column = 2)
  1131.  
  1132.         tk.Label(master, text = "Attribute", font = ftSmall).grid(row = 3, column = 0)
  1133.         tk.Label(master, text = "Value", font = ftSmall).grid(row = 3, column = 1)
  1134.         tk.Label(master, text = "Modifier", font = ftSmall).grid(row = 3, column = 2)
  1135.  
  1136.         tk.Label(master, text = "Strength", font = ftNormal).grid(row = 4, column = 0)
  1137.         tk.Label(master, text = "Dexterity", font = ftNormal).grid(row = 5, column = 0)
  1138.         tk.Label(master, text = "Constitution", font = ftNormal).grid(row = 6, column = 0)
  1139.         tk.Label(master, text = "Intelligence", font = ftNormal).grid(row = 7, column = 0)
  1140.         tk.Label(master, text = "Wisdom", font = ftNormal).grid(row = 8, column = 0)
  1141.         tk.Label(master, text = "Charisma", font = ftNormal).grid(row = 9, column = 0)
  1142.  
  1143.         self.STR = tk.Label(master, text = "?", width = 4, relief = "ridge", font = ftNormal)
  1144.         self.DEX = tk.Label(master, text = "?", width = 4, relief = "ridge", font = ftNormal)
  1145.         self.CON = tk.Label(master, text = "?", width = 4, relief = "ridge", font = ftNormal)
  1146.         self.INT = tk.Label(master, text = "?", width = 4, relief = "ridge", font = ftNormal)
  1147.         self.WIS = tk.Label(master, text = "?", width = 4, relief = "ridge", font = ftNormal)
  1148.         self.CHA = tk.Label(master, text = "?", width = 4, relief = "ridge", font = ftNormal)
  1149.  
  1150.         self.bSTR = tk.Label(master, text = "?", width = 4, relief = "ridge", font = ftNormal)
  1151.         self.bDEX = tk.Label(master, text = "?", width = 4, relief = "ridge", font = ftNormal)
  1152.         self.bCON = tk.Label(master, text = "?", width = 4, relief = "ridge", font = ftNormal)
  1153.         self.bINT = tk.Label(master, text = "?", width = 4, relief = "ridge", font = ftNormal)
  1154.         self.bWIS = tk.Label(master, text = "?", width = 4, relief = "ridge", font = ftNormal)
  1155.         self.bCHA = tk.Label(master, text = "?", width = 4, relief = "ridge", font = ftNormal)
  1156.  
  1157.         self.STR.grid(row = 4, column = 1)
  1158.         self.DEX.grid(row = 5, column = 1)
  1159.         self.CON.grid(row = 6, column = 1)
  1160.         self.INT.grid(row = 7, column = 1)
  1161.         self.WIS.grid(row = 8, column = 1)
  1162.         self.CHA.grid(row = 9, column = 1)
  1163.  
  1164.         self.bSTR.grid(row = 4, column = 2)
  1165.         self.bDEX.grid(row = 5, column = 2)
  1166.         self.bCON.grid(row = 6, column = 2)
  1167.         self.bINT.grid(row = 7, column = 2)
  1168.         self.bWIS.grid(row = 8, column = 2)
  1169.         self.bCHA.grid(row = 9, column = 2)
  1170.  
  1171.  
  1172.     def validate(self):
  1173.         if not self.rolled:
  1174.             mbx.showerror("Error", "You must roll at least once!")
  1175.             return 0
  1176.  
  1177.         elif not mbx.askyesno("Confirmation", "Are you sure you want these values for your main stats?"):
  1178.             return 0
  1179.  
  1180.         return 1
  1181.  
  1182.     def apply(self):
  1183.         resultString = ""
  1184.  
  1185.         resultString += self.STR["text"] + "|"
  1186.         resultString += self.DEX["text"] + "|"
  1187.         resultString += self.CON["text"] + "|"
  1188.         resultString += self.INT["text"] + "|"
  1189.         resultString += self.WIS["text"] + "|"
  1190.         resultString += self.CHA["text"] + "\n"
  1191.         resultString += self.bSTR["text"] + "|"
  1192.         resultString += self.bDEX["text"] + "|"
  1193.         resultString += self.bCON["text"] + "|"
  1194.         resultString += self.bINT["text"] + "|"
  1195.         resultString += self.bWIS["text"] + "|"
  1196.         resultString += self.bCHA["text"]
  1197.  
  1198.         self.result = resultString
  1199.  
  1200.     def setValues(self, master, tempStats):
  1201.         self.STR.config(text = str(tempStats[0]))
  1202.         self.DEX.config(text = str(tempStats[1]))
  1203.         self.CON.config(text = str(tempStats[2]))
  1204.         self.INT.config(text = str(tempStats[3]))
  1205.         self.WIS.config(text = str(tempStats[4]))
  1206.         self.CHA.config(text = str(tempStats[5]))
  1207.  
  1208.         self.bSTR.config(text = str((int(tempStats[0]) - 10) // 2))
  1209.         self.bDEX.config(text = str((int(tempStats[1]) - 10) // 2))
  1210.         self.bCON.config(text = str((int(tempStats[2]) - 10) // 2))
  1211.         self.bINT.config(text = str((int(tempStats[3]) - 10) // 2))
  1212.         self.bWIS.config(text = str((int(tempStats[4]) - 10) // 2))
  1213.         self.bCHA.config(text = str((int(tempStats[5]) - 10) // 2))
  1214.  
  1215.     def swap(self):
  1216.         if not self.rolled:
  1217.             mbx.showerror("Error", "You must roll at least once!")
  1218.             return
  1219.  
  1220.         tempStats = []
  1221.         localStats = ('STR', 'DEX', 'CON', 'INT', 'WIS', 'CHA')
  1222.  
  1223.         statA = localStats.index(self.swapOne.get())
  1224.         statB = localStats.index(self.swapTwo.get())
  1225.  
  1226.         if statA == statB:
  1227.             mbx.showerror("Error", "You can't swap a value with itself!")
  1228.             return
  1229.  
  1230.         tempStats.append(self.STR["text"])
  1231.         tempStats.append(self.DEX["text"])
  1232.         tempStats.append(self.CON["text"])
  1233.         tempStats.append(self.INT["text"])
  1234.         tempStats.append(self.WIS["text"])
  1235.         tempStats.append(self.CHA["text"])
  1236.  
  1237.         temp = tempStats[statA]
  1238.         tempStats[statA] = tempStats[statB]
  1239.         tempStats[statB] = temp
  1240.  
  1241.         self.setValues(self, tempStats)
  1242.  
  1243.     def rollStats(self):
  1244.         tempStats = [0, 0, 0, 0, 0, 0]
  1245.         tempRolls = []
  1246.         tempStr = ""
  1247.  
  1248.         if self.rollMode.get() == "six 1d20":
  1249.             for i in range(len(tempStats)):
  1250.                 tempStats[i] = rnd.randint(1, 20)
  1251.  
  1252.         else:
  1253.             for i in range(len(tempStats)):
  1254.                 for n in range(4):
  1255.                     tempRolls.append(rnd.randint(1,6))
  1256.  
  1257.                 tempRolls.remove(min(tempRolls))
  1258.  
  1259.                 tempStats[i] = sum(tempRolls)
  1260.  
  1261.                 tempRolls = []
  1262.  
  1263.         self.setValues(self, tempStats)
  1264.  
  1265.         self.rolled = True
  1266. #Guides the player through character creation
  1267. def newCharacter():
  1268.     if not mbx.askyesno("Warning! Data Loss Possibility Detected!", "Making a new character will erase all current data\nAre you sure you want to continue?"):
  1269.         return
  1270.  
  1271.     tempInfo = []
  1272.     tempHealth = []
  1273.     tempExp = []
  1274.     tempMStats = []
  1275.     tempBStats = []
  1276.     tempInt = 0
  1277.     tempIntB = 0
  1278.     tempStr = ""
  1279.     tempCount = 0
  1280.     infoChoices = ["name", "class", "deity", "race", "gender", "age", "height", "unit", "weight", "unit", "hair color", "eye color", "currency"]
  1281.     statChoices = ["Strength", "Dexterity", "Constitution", "Intelligence", "Wisdom", "Charisma"]
  1282.  
  1283.     while len(tempInfo) < 14:
  1284.         if tempCount < 5 or tempCount > 9:
  1285.             tempStr = sdg.askstring("New Character: Info", "Enter your " + infoChoices[tempCount] + ":")
  1286.             if type(tempStr) == str:
  1287.                 tempInfo.append(tempStr)
  1288.             else:
  1289.                 return
  1290.  
  1291.             if tempCount == 12:
  1292.                 tempInt = sdg.askinteger("New Character: Info", "Enter how much currency you have:")
  1293.                 if type(tempInt) == int:
  1294.                     tempInfo.append(tempInt)
  1295.                 else:
  1296.                     return
  1297.             else:
  1298.                 tempCount += 1
  1299.  
  1300.         elif tempCount > 5 and tempCount < 10:
  1301.             tempStr = sdg.askstring("New Character: Info", "Enter your unit of " + infoChoices[tempCount] + ":")
  1302.             if type(tempStr) != str:
  1303.                 return
  1304.  
  1305.             tempInt = sdg.askinteger("New Character: Info", "Enter your " + infoChoices[tempCount] + ":")
  1306.             if type(tempInt) == int:
  1307.                 tempInfo.append(tempInt)
  1308.                 tempInfo.append(tempStr)
  1309.                 tempCount += 2
  1310.             else:
  1311.                 return
  1312.  
  1313.         elif tempCount == 5:
  1314.             tempInt = sdg.askinteger("New Character: Info", "Enter your " + infoChoices[tempCount] + ":")
  1315.             if type(tempInt) == int:
  1316.                 tempInfo.append(tempInt)
  1317.                 tempCount += 1
  1318.             else:
  1319.                 return
  1320.  
  1321.     tempInt = sdg.askinteger("New Character: Health", "Enter your initial maximum health points:")
  1322.     if type(tempInt) != int:
  1323.         return
  1324.  
  1325.     tempHealth.append(tempInt)
  1326.     tempHealth.append(tempInt)
  1327.  
  1328.     tempExp.append(1)
  1329.     tempExp.append(0)
  1330.  
  1331.     if LEVLVar.get():
  1332.         tempExp.append(300)
  1333.     else:
  1334.         tempExp.append(110)
  1335.  
  1336.     tempInt = newCharacterStatRoot(base).result
  1337.     if type(tempInt) != int:
  1338.         return
  1339.  
  1340.     if tempInt == 0:
  1341.         tempStr = pointBuyRoot(base).result
  1342.     if tempInt == 1:
  1343.         tempStr = diceRollStatsRoot(base).result
  1344.  
  1345.     if type(tempStr) != str:
  1346.         return
  1347.  
  1348.     if tempInt in (0, 1):
  1349.         for s in tempStr.split()[0].split('|'):
  1350.             tempMStats.append(int(s))
  1351.  
  1352.         for s in tempStr.split()[1].split('|'):
  1353.             tempBStats.append(int(s))
  1354.  
  1355.     elif tempInt == 2:
  1356.         tempCount = 0
  1357.  
  1358.         while len(tempMStats) < 6 and len(tempBStats) < 6:
  1359.             tempInt = sdg.askinteger("New Character: Manual Stats", "Enter your " + statChoices[tempCount] + ":")
  1360.             if type(tempInt) != int:
  1361.                 return
  1362.  
  1363.             tempIntB = (tempInt - 10) // 2
  1364.  
  1365.             tempMStats.append(tempInt)
  1366.             tempBStats.append(tempIntB)
  1367.             tempCount += 1
  1368.  
  1369.     tempCount = 0
  1370.  
  1371.     for bit in tempInfo:
  1372.         info[tempCount] = bit
  1373.         tempCount += 1
  1374.  
  1375.     tempCount = 0
  1376.  
  1377.     for bit in tempHealth:
  1378.         health[tempCount] = bit
  1379.         tempCount += 1
  1380.  
  1381.     tempCount = 0
  1382.  
  1383.     for bit in tempExp:
  1384.         experience[tempCount] = bit
  1385.         tempCount += 1
  1386.  
  1387.     tempCount = 0
  1388.  
  1389.     for bit in tempMStats:
  1390.         mainStats[tempCount] = bit
  1391.         tempCount += 1
  1392.  
  1393.     tempCount = 0
  1394.  
  1395.     for bit in tempBStats:
  1396.         bonusStats[tempCount] = bit
  1397.         tempCount += 1
  1398.  
  1399.     while len(skills) > 0:
  1400.         del skills[0]
  1401.  
  1402.     while len(abilities) > 0:
  1403.         del abilities[0]
  1404.  
  1405.     while len(inventory) > 0:
  1406.         del inventory[0]
  1407.  
  1408.     refrSTAT()
  1409.     refrINFO()
  1410.     refrSKIL()
  1411.     refrABIL()
  1412.     refrINVT()
  1413.  
  1414.     mbx.showinfo("New Character: Complete", "Done! Your character's main information and stats are ready. You might want to add some abilities or skills for additional bits of information, such as racial bonuses, character backstory, or starting abilities. Good luck, adventurer!")
  1415. #Saves the current character to a .dat file
  1416. def saveCharacter():
  1417.     fileName = sdg.askstring("Save Character", "[Files are saved to the directory\nwhere this program is run]\nEnter the name of the file to save to:")
  1418.     if type(fileName) != str:
  1419.         return
  1420.  
  1421.     fileName += ".dat"
  1422.  
  1423.     if os.path.isfile(fileName):
  1424.         if not mbx.askyesno("Warning! File Already Exists!", "Do you want to overwrite " + fileName + "?"):
  1425.             return
  1426.  
  1427.     saveFile = open(fileName, "w")
  1428.  
  1429.     dlm = " || "
  1430.     adlm = " |\n"
  1431.     nl = "\n\n"
  1432.  
  1433.     temp = 0
  1434.  
  1435.     for bit in info:
  1436.         saveFile.write(str(bit))
  1437.  
  1438.         if temp == 13:
  1439.             saveFile.write(nl)
  1440.         else:
  1441.             saveFile.write(dlm)
  1442.  
  1443.         temp += 1
  1444.  
  1445.     temp = 0
  1446.  
  1447.     for bit in health:
  1448.         saveFile.write(str(bit))
  1449.  
  1450.         if temp == 1:
  1451.             saveFile.write(nl)
  1452.         else:
  1453.             saveFile.write(dlm)
  1454.  
  1455.         temp += 1
  1456.  
  1457.     temp = 0
  1458.  
  1459.     for bit in experience:
  1460.         saveFile.write(str(bit))
  1461.  
  1462.         if temp == 2:
  1463.             saveFile.write(nl)
  1464.         else:
  1465.             saveFile.write(dlm)
  1466.  
  1467.         temp += 1
  1468.  
  1469.     temp = 0
  1470.  
  1471.     for bit in mainStats:
  1472.         saveFile.write(str(bit))
  1473.  
  1474.         if temp == 5:
  1475.             saveFile.write(nl)
  1476.         else:
  1477.             saveFile.write(dlm)
  1478.  
  1479.         temp += 1
  1480.  
  1481.     temp = 0
  1482.  
  1483.     for bit in bonusStats:
  1484.         saveFile.write(str(bit))
  1485.  
  1486.         if temp == 5:
  1487.             saveFile.write(nl)
  1488.         else:
  1489.             saveFile.write(dlm)
  1490.  
  1491.         temp += 1
  1492.  
  1493.     temp = 1
  1494.  
  1495.     for sk in skills:
  1496.         saveFile.write(str(sk[0]) + dlm + sk[1])
  1497.  
  1498.         if temp != len(skills):
  1499.             saveFile.write(adlm)
  1500.  
  1501.         temp += 1
  1502.  
  1503.     saveFile.write(nl)
  1504.  
  1505.     temp = 1
  1506.  
  1507.     for ab in abilities:
  1508.         saveFile.write(str(ab[0]) + dlm + ab[1] + dlm + ab[2])
  1509.  
  1510.         if temp != len(abilities):
  1511.             saveFile.write(adlm)
  1512.  
  1513.         temp += 1
  1514.  
  1515.     saveFile.write(nl)
  1516.  
  1517.     temp = 1
  1518.  
  1519.     for item in inventory:
  1520.         tempAux = 1
  1521.  
  1522.         for bit in item:
  1523.             saveFile.write(str(bit))
  1524.             if tempAux < 9:
  1525.                 saveFile.write(dlm)
  1526.  
  1527.             tempAux += 1
  1528.  
  1529.         if temp != len(inventory):
  1530.             saveFile.write(adlm)
  1531.  
  1532.         temp += 1
  1533.  
  1534.     saveFile.close()
  1535.  
  1536.     mbx.showinfo("Save Character", "Saved!\nCheck the working directory of this program for the file.")
  1537. #Loads a character from a .dat file
  1538. def loadCharacter():
  1539.     loaded = False
  1540.  
  1541.     while not loaded:
  1542.         try:
  1543.             fileName = sdg.askstring("Load Character", "[Files are loaded from the directory\nwhere this program is run]\nEnter the name of the file to load from:")
  1544.             if type(fileName) != str:
  1545.                 return
  1546.  
  1547.             fileName += ".dat"
  1548.             loadFile = open(fileName, "r")
  1549.             loaded = True
  1550.  
  1551.         except FileNotFoundError:
  1552.             mbx.showerror("Error", "File not found!")
  1553.  
  1554.     if mbx.askyesno("Leveling Standard", "Do you want to use the 5E Experience Point brackets instead of C^2's Experience Formula?"):
  1555.         LEVLVar.set(True)
  1556.     else:
  1557.         LEVLVar.set(False)
  1558.  
  1559.     dlm = " || "
  1560.     adlm = " |\n"
  1561.     nl = "\n\n"
  1562.  
  1563.     contents = loadFile.read().split(nl)
  1564.  
  1565.     tempCountA = 0
  1566.  
  1567.     try:
  1568.         for bit in contents:
  1569.             tempList = []
  1570.  
  1571.             if adlm in bit:
  1572.                 tempList = bit.split(adlm)
  1573.                 tempCountB = 0
  1574.  
  1575.                 for item in tempList:
  1576.                     tempList[tempCountB] = item.split(dlm)
  1577.                     tempCountC = 0
  1578.  
  1579.                     for el in tempList[tempCountB]:
  1580.                         if el == "True":
  1581.                             tempList[tempCountB][tempCountC] = True
  1582.                         elif el == "False":
  1583.                             tempList[tempCountB][tempCountC] = False
  1584.                         else:
  1585.                             try:
  1586.                                 tempList[tempCountB][tempCountC] = int(el)
  1587.                
  1588.                             except ValueError:
  1589.                                 try:
  1590.                                     tempList[tempCountB][tempCountC] = float(el)
  1591.                                 except ValueError:
  1592.                                     pass
  1593.    
  1594.                         tempCountC += 1
  1595.    
  1596.                     tempCountB += 1
  1597.  
  1598.             elif dlm in bit:
  1599.                 tempList = bit.split(dlm)
  1600.                 tempCountB = 0
  1601.  
  1602.                 for el in tempList:
  1603.                     try:
  1604.                         tempList[tempCountB] = int(el)
  1605.                
  1606.                     except ValueError:
  1607.                         try:
  1608.                             tempList[tempCountB] = float(el)
  1609.                         except ValueError:
  1610.                             pass
  1611.        
  1612.                     tempCountB += 1
  1613.    
  1614.             contents[tempCountA] = tempList
  1615.  
  1616.             tempCountA += 1
  1617.  
  1618.     except:
  1619.         mbx.showerror("Error", "Unable to Load File!")
  1620.         return
  1621.  
  1622.     tempCount = 0
  1623.  
  1624.     for bit in contents[0]:
  1625.         info[tempCount] = bit
  1626.         tempCount += 1
  1627.  
  1628.     tempCount = 0
  1629.  
  1630.     for bit in contents[1]:
  1631.         health[tempCount] = bit
  1632.         tempCount += 1
  1633.  
  1634.     tempCount = 0
  1635.  
  1636.     for bit in contents[2]:
  1637.         experience[tempCount] = bit
  1638.         tempCount += 1
  1639.  
  1640.     tempCount = 0
  1641.  
  1642.     for bit in contents[3]:
  1643.         mainStats[tempCount] = bit
  1644.         tempCount += 1
  1645.  
  1646.     tempCount = 0
  1647.  
  1648.     for bit in contents[4]:
  1649.         bonusStats[tempCount] = bit
  1650.         tempCount += 1
  1651.  
  1652.     while len(skills) > 0:
  1653.         del skills[0]
  1654.  
  1655.     if len(contents[5]) > 0:
  1656.         if type(contents[5][0]) is list:
  1657.             for bit in contents[5]:
  1658.                 skills.append(bit)
  1659.         else:
  1660.             skills.append(contents[5])
  1661.  
  1662.     while len(abilities) > 0:
  1663.         del abilities[0]
  1664.  
  1665.     if len(contents[6]) > 0:
  1666.         if type(contents[6][0]) is list:
  1667.             for bit in contents[6]:
  1668.                 abilities.append(bit)
  1669.         else:
  1670.             abilities.append(contents[6])
  1671.  
  1672.     while len(inventory) > 0:
  1673.         del inventory[0]
  1674.  
  1675.     if len(contents[7]) > 0:
  1676.         if type(contents[7][0]) is list:
  1677.             for bit in contents[7]:
  1678.                 inventory.append(bit)
  1679.         else:
  1680.             inventory.append(contents[7])
  1681.  
  1682.     mbx.showinfo("Load Character", "Loaded!\nYour journey continues...")
  1683.     refrSTAT()
  1684.     refrINFO()
  1685.     refrINVT()
  1686.     refrSKIL()
  1687.     refrABIL()
  1688. #Lists for main program data
  1689. mainStats = [10, 10, 10, 10, 10, 10]
  1690. bonusStats = [0, 0, 0, 0, 0, 0]
  1691. savingThrows = [0, 0, 0]
  1692. health = [0, 10]
  1693. experience = [1, 0, 300]
  1694. info = ["name", "class", "deity", "race", "gender", 18, 170, "cm", 70, "kg", "brown", "black", "currency", 0]
  1695. skills = []
  1696. abilities = []
  1697. inventory = []
  1698. brackets5E = [0, 300, 900, 2700, 6500, 14000, 23000, 34000, 48000, 64000, 85000, 100000, 120000, 140000, 165000, 195000, 225000, 265000, 305000, 355000]
  1699. #Creation of base tk window
  1700. base = tk.Tk()
  1701. base.protocol("WM_DELETE_WINDOW", exitOverride)
  1702. #Declaration of fonts
  1703. ftSmall = tkf.Font(family = "Consolas", size = 8)
  1704. ftNormal = tkf.Font(family = "Consolas", size = 10)
  1705. ftNormUnd = tkf.Font(family = "Consolas", size = 10, underline = 1)
  1706. ftLarge = tkf.Font(family = "Consolas", size = 12)
  1707. ftTitle = tkf.Font(family = "Consolas", size = 12, weight = "bold", slant = "italic")
  1708. ftBigTitle = tkf.Font(family = "Consolas", size = 16, weight = "bold", slant = "italic")
  1709. ftName = tkf.Font(family = "Consolas", size = 16, weight = "bold")
  1710. ftSubtitle = tkf.Font(family = "Consolas", size = 12, slant = "italic")
  1711. ftDice = tkf.Font(family = "Consolas", size = 12, weight = "bold")
  1712. #Frame for stats
  1713. STATPnl = tk.Frame(base, bd = 4, relief = "groove")
  1714. STATPnl.grid(row = 1, column = 0, rowspan = 2, padx = 8, sticky = "n")
  1715. #Stats labels and buttons
  1716. STATTitl = tk.Label(STATPnl, text = "Stats", width = 8, bd = 4, relief = "raised", font = ftTitle)
  1717. LEVLLbl = tk.Label(STATPnl, width = 10, relief = "ridge", font = ftLarge)
  1718. LEVLVar = tk.BooleanVar()
  1719. LEVLVar.set(True)
  1720. LEVLChk = tk.Checkbutton(STATPnl, text = "5E XP", command = ChangeXP, variable = LEVLVar, font = ftNormal)
  1721. XPLbl = tk.Label(STATPnl, width = 16, relief = "ridge", font = ftLarge, anchor = "w")
  1722. XPPlusBtn = tk.Button(STATPnl, text = "+", command = XPUp, cursor = "hand2", font = ftNormal)
  1723.  
  1724. HPLbl = tk.Label(STATPnl, width = 12, relief = "ridge", font = ftLarge, anchor = "w")
  1725. HPPLUSBtn = tk.Button(STATPnl, text = "+", command = HPUp, cursor = "hand2", font = ftNormal)
  1726. HPMINSBtn = tk.Button(STATPnl, text = "-", command = HPDown, cursor = "hand2", font = ftNormal)
  1727.  
  1728. STRLbl = tk.Label(STATPnl, width = 10, relief = "ridge", font = ftLarge)
  1729. DEXLbl = tk.Label(STATPnl, width = 10, relief = "ridge", font = ftLarge)
  1730. CONLbl = tk.Label(STATPnl, width = 10, relief = "ridge", font = ftLarge)
  1731. INTLbl = tk.Label(STATPnl, width = 10, relief = "ridge", font = ftLarge)
  1732. WISLbl = tk.Label(STATPnl, width = 10, relief = "ridge", font = ftLarge)
  1733. CHALbl = tk.Label(STATPnl, width = 10, relief = "ridge", font = ftLarge)
  1734.  
  1735. STRBLbl = tk.Label(STATPnl, width = 4, relief = "ridge", font = ftLarge)
  1736. DEXBLbl = tk.Label(STATPnl, width = 4, relief = "ridge", font = ftLarge)
  1737. CONBLbl = tk.Label(STATPnl, width = 4, relief = "ridge", font = ftLarge)
  1738. INTBLbl = tk.Label(STATPnl, width = 4, relief = "ridge", font = ftLarge)
  1739. WISBLbl = tk.Label(STATPnl, width = 4, relief = "ridge", font = ftLarge)
  1740. CHABLbl = tk.Label(STATPnl, width = 4, relief = "ridge", font = ftLarge)
  1741.  
  1742. FORTLbl = tk.Label(STATPnl, width = 16, anchor = "e", relief = "ridge", font = ftNormal)
  1743. REFLLbl = tk.Label(STATPnl, width = 16, anchor = "e", relief = "ridge", font = ftNormal)
  1744. WILLLbl = tk.Label(STATPnl, width = 16, anchor = "e", relief = "ridge", font = ftNormal)
  1745. STATEDITBtn = tk.Button(STATPnl, text = "Edit Stats", width = 10, command = editStat, cursor = "hand2", font = ftSmall)
  1746. #Grid assignments of stats elements
  1747. STATTitl.grid(row = 0, columnspan = 3, pady = 4)
  1748. LEVLLbl.grid(row = 1, column = 0, columnspan = 3, pady = 2)
  1749. XPLbl.grid(row = 2, column = 0, columnspan = 2, padx = 4, pady = 2, sticky = "W")
  1750. XPPlusBtn.grid(row = 2, column = 2)
  1751.  
  1752. HPLbl.grid(row = 3, column = 0, padx = 4, pady = 2, sticky = "W")
  1753. HPPLUSBtn.grid(row = 3, column = 1, padx = 2)
  1754. HPMINSBtn.grid(row = 3, column = 2, padx = 2)
  1755.  
  1756. STRLbl.grid(row = 4, column = 0, padx = 4, pady = 2, sticky = "E")
  1757. DEXLbl.grid(row = 5, column = 0, padx = 4, pady = 2, sticky = "E")
  1758. CONLbl.grid(row = 6, column = 0, padx = 4, pady = 2, sticky = "E")
  1759. INTLbl.grid(row = 7, column = 0, padx = 4, pady = 2, sticky = "E")
  1760. WISLbl.grid(row = 8, column = 0, padx = 4, pady = 2, sticky = "E")
  1761. CHALbl.grid(row = 9, column = 0, padx = 4, pady = 2, sticky = "E")
  1762.  
  1763. STRBLbl.grid(row = 4, column = 1, columnspan = 2, padx = 4, pady = 2)
  1764. DEXBLbl.grid(row = 5, column = 1, columnspan = 2, padx = 4, pady = 2)
  1765. CONBLbl.grid(row = 6, column = 1, columnspan = 2, padx = 4, pady = 2)
  1766. INTBLbl.grid(row = 7, column = 1, columnspan = 2, padx = 4, pady = 2)
  1767. WISBLbl.grid(row = 8, column = 1, columnspan = 2, padx = 4, pady = 2)
  1768. CHABLbl.grid(row = 9, column = 1, columnspan = 2, padx = 4, pady = 2)
  1769.  
  1770. FORTLbl.grid(row = 10, columnspan = 3, padx = 4, pady = 2)
  1771. REFLLbl.grid(row = 11, columnspan = 3, padx = 4, pady = 2)
  1772. WILLLbl.grid(row = 12, columnspan = 3, padx = 4, pady = 2)
  1773. STATEDITBtn.grid(row = 13, column = 0, padx = 4, pady = 2)
  1774. LEVLChk.grid(row = 13, column = 1, columnspan = 2)
  1775.  
  1776. refrSTAT()
  1777. #Frame for information
  1778. INFOPnl = tk.Frame(base, bd = 4, relief = "groove")
  1779. INFOPnl.grid(row = 1, column = 1, sticky = "nw")
  1780. #Information labels and buttons
  1781. INFOTitl = tk.Label(INFOPnl, text ="Information", width = 32, bd = 4, relief = "raised", font = ftTitle)
  1782. INFOTitl.grid(row = 0, columnspan = 6, pady = 4)
  1783.  
  1784. NAMELbl = tk.Label(INFOPnl, width = 36, bd = 4, relief = "ridge", font = ftName)
  1785. CLSSLbl = tk.Label(INFOPnl, width = 24, relief = "ridge", font = ftLarge)
  1786. DETYLbl = tk.Label(INFOPnl, width = 24, relief = "ridge", font = ftLarge)
  1787. RACELbl = tk.Label(INFOPnl, width = 24, relief = "ridge", font = ftLarge)
  1788. GNDRLbl = tk.Label(INFOPnl, width = 24, relief = "ridge", font = ftLarge)
  1789. AYGELbl = tk.Label(INFOPnl, width = 8, relief = "ridge", font = ftLarge)
  1790. HGHTLbl = tk.Label(INFOPnl, width = 8, relief = "ridge", font = ftLarge)
  1791. WGHTLbl = tk.Label(INFOPnl, width = 8, relief = "ridge", font = ftLarge)
  1792. INFOEDITBtn = tk.Button(INFOPnl, text = "Edit Info", width = 8, command = editInfo, cursor = "hand2", font = ftSmall)
  1793. HAIRLbl = tk.Label(INFOPnl, width = 24, relief = "ridge", font = ftLarge)
  1794. EYESLbl = tk.Label(INFOPnl, width = 24, relief = "ridge", font = ftLarge)
  1795. MONYLbl = tk.Label(INFOPnl, width = 32, relief = "ridge", font = ftLarge)
  1796. MONYCHNGBtn = tk.Button(INFOPnl, text = "Credit/Debit", width = 12, command = changeMoney, cursor = "hand2", font = ftSmall)
  1797. #Grid assignments of information elements
  1798. NAMELbl.grid(row = 1, columnspan = 6, padx = 12, pady = 4)
  1799. CLSSLbl.grid(row = 2, column = 0, columnspan = 3, padx = 4)
  1800. DETYLbl.grid(row = 3, column = 0, columnspan = 3, padx = 4)
  1801. HAIRLbl.grid(row = 4, column = 0, columnspan = 3, padx = 4)
  1802. RACELbl.grid(row = 2, column = 3, columnspan = 3, pady = 4)
  1803. GNDRLbl.grid(row = 3, column = 3, columnspan = 3, pady = 4)
  1804. EYESLbl.grid(row = 4, column = 3, columnspan = 3, pady = 4)
  1805. AYGELbl.grid(row = 5, column = 1, pady = 4)
  1806. HGHTLbl.grid(row = 5, column = 2)
  1807. WGHTLbl.grid(row = 5, column = 3)
  1808. INFOEDITBtn.grid(row = 5, column = 4)
  1809. MONYLbl.grid(row = 6, column = 1, columnspan = 3)
  1810. MONYCHNGBtn.grid(row = 6, column = 4, pady = 11)
  1811.  
  1812. refrINFO()
  1813. #Frame for inventory
  1814. INVTPnl = tk.Frame(base, bd = 4, relief = "groove")
  1815. INVTPnl.grid(row = 2, column = 1, rowspan = 2, columnspan = 2, pady = 8, sticky = "w")
  1816. #Inventory elements
  1817. INVTTitl = tk.Label(INVTPnl, text = "Inventory", width = 24, bd = 4, relief = "raised", font = ftTitle)
  1818. INVTNEWWBtn = tk.Button(INVTPnl, text = "Create Item", width = 12, command = newItem, cursor = "hand2", font = ftSmall)
  1819. INVTEDITBtn = tk.Button(INVTPnl, text = "Edit Item", width = 12, command = editItem, cursor = "hand2", font = ftSmall)
  1820. INVTDELTBtn = tk.Button(INVTPnl, text = "Delete Item", width = 12, command = deleteItem, cursor = "hand2", font = ftSmall)
  1821. INVTINSPBtn = tk.Button(INVTPnl, text = "Inspect Item", width = 12, command = inspectItem, cursor = "hand2", font = ftSmall)
  1822. INVTSORTBtn = tk.Button(INVTPnl, text = "Sort Items", width = 12, command = sortItems, cursor = "hand2", font = ftSmall)
  1823. INVTLbl = tk.Label(INVTPnl, text = "Name\t\t\t\t\tCount\tWeight\tDice\tCharges\tEquipped", font = ftNormUnd)
  1824. INVTTxt = tk.Listbox(INVTPnl, height = 11, width = 80, cursor = "cross", font = ftNormal)
  1825. IVNTScr = tk.Scrollbar(INVTPnl, orient = "vertical", command = INVTTxt.yview)
  1826. INVTTxt.config(yscrollcommand = IVNTScr.set)
  1827. INVTENCMLbl = tk.Label(INVTPnl, text = "Encumberance:", width = 24, anchor = "w", relief = "ridge", font = ftNormal)
  1828. #Grid assignments of inventory elements
  1829. INVTTitl.grid(row = 0, column = 0, pady = 4)
  1830. INVTNEWWBtn.grid(row = 0, column = 1)
  1831. INVTEDITBtn.grid(row = 0, column = 2)
  1832. INVTDELTBtn.grid(row = 1, column = 2, columnspan = 2)
  1833. INVTINSPBtn.grid(row = 1, column = 1, columnspan = 2)
  1834. INVTSORTBtn.grid(row = 0, column = 3)
  1835. INVTLbl.grid(row = 2, columnspan = 4, sticky = "w")
  1836. INVTTxt.grid(row = 3, column = 0, columnspan = 4)
  1837. IVNTScr.grid(row = 2, column = 4, rowspan = 2, sticky = "ns")
  1838. INVTENCMLbl.grid(row = 4, columnspan = 5, pady = 2, sticky = "e")
  1839.  
  1840. refrINVT()
  1841. #Frame for dice
  1842. DICEPnl = tk.Frame(base, bd = 4, relief = "groove")
  1843. DICEPnl.grid(row = 3, column = 0)
  1844. #Dice labels and buttons
  1845. DICETitl = tk.Label(DICEPnl, text = "Dice", width = 8, bd = 4, relief = "raised", font = ftTitle)
  1846. DICELbl = tk.Label(DICEPnl, width = 13, text = "0 | d?", relief = "groove", font = ftDice)
  1847. DICEd2Btn = tk.Button(DICEPnl, width = 4, text = "Coin", command = rollDice(2), cursor = "hand2", font = ftNormal)
  1848. DICEd4Btn = tk.Button(DICEPnl, width = 4, text = "d4", command = rollDice(4), cursor = "hand2", font = ftNormal)
  1849. DICEd6Btn = tk.Button(DICEPnl, width = 4, text = "d6", command = rollDice(6), cursor = "hand2", font = ftNormal)
  1850. DICEd8Btn = tk.Button(DICEPnl, width = 4, text = "d8", command = rollDice(8), cursor = "hand2", font = ftNormal)
  1851. DICEd10Btn = tk.Button(DICEPnl, width = 4, text = "d10", command = rollDice(10), cursor = "hand2", font = ftNormal)
  1852. DICEd12Btn = tk.Button(DICEPnl, width = 4, text = "d12", command = rollDice(12), cursor = "hand2", font = ftNormal)
  1853. DICEd20Btn = tk.Button(DICEPnl, width = 4, text = "d20", command = rollDice(20), cursor = "hand2", font = ftNormal)
  1854. DICEd100Btn = tk.Button(DICEPnl, width = 4, text = "d100", command = rollDice(100), cursor = "hand2", font = ftNormal)
  1855. DICERstBtn = tk.Button(DICEPnl, width = 4, text = "Reset", command = rollDice(0), cursor = "hand2", font = ftNormal)
  1856. #Grid assignments of dice elements
  1857. DICETitl.grid(row = 0, column = 0, columnspan = 3, pady = 4)
  1858. DICELbl.grid(row = 1, column = 0, columnspan = 3, padx = 38, pady = 4)
  1859. DICEd2Btn.grid(row = 2, column = 0, pady = 2)
  1860. DICEd4Btn.grid(row = 2, column = 1)
  1861. DICEd6Btn.grid(row = 2, column = 2)
  1862. DICEd8Btn.grid(row = 3, column = 0, pady = 2)
  1863. DICEd10Btn.grid(row = 3, column = 1)
  1864. DICEd12Btn.grid(row = 3, column = 2)
  1865. DICERstBtn.grid(row = 4, column = 0, pady = 2)
  1866. DICEd20Btn.grid(row = 4, column = 1)
  1867. DICEd100Btn.grid(row = 4, column = 2)
  1868. #Panel for skills
  1869. SKILPnl = tk.Frame(base, bd = 4, relief = "groove")
  1870. SKILPnl.grid(row = 2, column = 3, rowspan = 2, padx = 8, pady = 8, sticky = "ne")
  1871. #Skill elements
  1872. SKILTitl = tk.Label(SKILPnl, text = "Skills", width = 8, bd = 4, relief = "raised", font = ftTitle)
  1873. SKILTxt = tk.Listbox(SKILPnl, height = 9, width = 32, cursor = "cross", font = ftNormal)
  1874. SKILScrV = tk.Scrollbar(SKILPnl, orient = "vertical", command = SKILTxt.yview)
  1875. SKILScrH = tk.Scrollbar(SKILPnl, orient = "horizontal", command = SKILTxt.xview)
  1876. SKILTxt.config(yscrollcommand = SKILScrV.set, xscrollcommand = SKILScrH.set)
  1877. SKILNEWWBtn = tk.Button(SKILPnl, text = "Create Skill", width = 12, command = newSkill, cursor = "hand2", font = ftSmall)
  1878. SKILEDITBtn = tk.Button(SKILPnl, text = "Edit Skill", width = 12, command = editSkill, cursor = "hand2", font = ftSmall)
  1879. SKILDELTBtn = tk.Button(SKILPnl, text = "Delete Skill", width = 12, command = deleteSkill, cursor = "hand2", font = ftSmall)
  1880. SKILSORTBtn = tk.Button(SKILPnl, text = "Sort Skills", width = 12, command = sortSkills, cursor = "hand2", font = ftSmall)
  1881. SKILSCORVar = tk.BooleanVar()
  1882. SKILSCORVar.set(False)
  1883. SKILSCORSwt = tk.Checkbutton(SKILPnl, text = "Apply +/- Skills To Stats", command = changeScores, variable = SKILSCORVar, font = ftSmall)
  1884. SKILSCORBtn = tk.Button(SKILPnl, text = "?", command = showPrefixInfo, cursor = "hand2", font = ftSmall)
  1885. #Grid assignments of skill elements
  1886. SKILTitl.grid(row = 0, columnspan = 3, pady = 4)
  1887. SKILTxt.grid(row = 4, column = 0, columnspan = 2)
  1888. SKILScrV.grid(row = 4, column = 2, rowspan = 2, sticky = "ns")
  1889. SKILScrH.grid(row = 5, column = 0, columnspan = 2, pady = 2, sticky = "we")
  1890. SKILNEWWBtn.grid(row = 1, column = 0)
  1891. SKILEDITBtn.grid(row = 1, column = 1)
  1892. SKILDELTBtn.grid(row = 2, column = 0)
  1893. SKILSORTBtn.grid(row = 2, column = 1)
  1894. SKILSCORSwt.grid(row = 3, column = 0, columnspan = 2, padx = 8, sticky = "w")
  1895. SKILSCORBtn.grid(row = 3, column = 1, padx = 8, sticky = "e")
  1896.  
  1897. refrSKIL()
  1898. #Frame for abilities
  1899. ABILPnl = tk.Frame(base, bd = 4, relief = "groove")
  1900. ABILPnl.grid(row = 1, column = 2, columnspan = 2, padx = 8, sticky = "n")
  1901. #Ability elements
  1902. ABILTitl = tk.Label(ABILPnl, text = "Abilities", width = 16, bd = 4, relief = "raised", font = ftTitle)
  1903. ABILTxt = tk.Listbox(ABILPnl, height = 10, width = 48, cursor = "cross", font = ftNormal)
  1904. ABILScrV = tk.Scrollbar(ABILPnl, orient = "vertical", command = ABILTxt.yview)
  1905. ABILScrH = tk.Scrollbar(ABILPnl, orient = "horizontal", command = ABILTxt.xview)
  1906. ABILTxt.config(yscrollcommand = ABILScrV.set, xscrollcommand = ABILScrH.set)
  1907. ABILNEWWBtn = tk.Button(ABILPnl, text = "Create Ability", width = 12, command = newAbility, cursor = "hand2", font = ftSmall)
  1908. ABILEDITBtn = tk.Button(ABILPnl, text = "Edit Ability", width = 12, command = editAbility, cursor = "hand2", font = ftSmall)
  1909. ABILDELTBtn = tk.Button(ABILPnl, text = "Delete Ability", width = 12, command = deleteAbility, cursor = "hand2", font = ftSmall)
  1910. ABILINSPBtn = tk.Button(ABILPnl, text = "Inspect Ability", width = 12, command = inspectAbility, cursor = "hand2", font = ftSmall)
  1911. ABILSORTBtn = tk.Button(ABILPnl, text = "Sort Abilities", width = 12, command = sortAbilities, cursor = "hand2", font = ftSmall)
  1912. #Grid assignments of ability elements
  1913. ABILTitl.grid(row = 0, columnspan = 4, pady = 4)
  1914. ABILTxt.grid(row = 3, column = 0, columnspan = 3)
  1915. ABILScrV.grid(row = 3, column = 3, rowspan = 2, sticky = "ns")
  1916. ABILScrH.grid(row = 4, columnspan = 3, sticky = "we")
  1917. ABILNEWWBtn.grid(row = 1, column = 0, sticky = "e")
  1918. ABILEDITBtn.grid(row = 1, column = 1, sticky = "e")
  1919. ABILSORTBtn.grid(row = 1, column = 2, sticky = "e")
  1920. ABILINSPBtn.grid(row = 2, column = 0, columnspan = 2)
  1921. ABILDELTBtn.grid(row = 2, column = 1, columnspan = 2)
  1922. #Frame for menu
  1923. MENUPnl = tk.Frame(base, bd = 4, relief = "groove")
  1924. MENUPnl.grid(row = 0, columnspan = 4, pady = 8)
  1925. #Menu labels and buttons
  1926. MENUTitl = tk.Label(MENUPnl, text = "C²'s D&D Character Sheet", width = 64, bd = 4, relief = "raised", font = ftBigTitle)
  1927. MENUNEWWBtn = tk.Button(MENUPnl, text = "New Character", width = 16, command = newCharacter, cursor = "hand2", font = ftLarge)
  1928. MENUSAVEBtn = tk.Button(MENUPnl, text = "Save Character", width = 16, command = saveCharacter, cursor = "hand2", font = ftLarge)
  1929. MENULOADBtn = tk.Button(MENUPnl, text = "Load Character", width = 16, command = loadCharacter, cursor = "hand2", font = ftLarge)
  1930. MENUVERS = tk.Label(MENUPnl, text = "Version 1.2.2", width = 16, bd = 4, relief = "ridge", font = ftSubtitle)
  1931. #Grid assignments of menu elements
  1932. MENUTitl.grid(row = 0, columnspan = 4, padx = 16, pady = 4)
  1933. MENUNEWWBtn.grid(row = 1, column = 0, pady = 4)
  1934. MENUSAVEBtn.grid(row = 1, column = 1)
  1935. MENULOADBtn.grid(row = 1, column = 2)
  1936. MENUVERS.grid(row = 1, column = 3)
  1937. #Initialization of main window and final settings
  1938. base.title("DnD Character Sheet")
  1939. base.resizable(False, False)
  1940. base.mainloop()
RAW Paste Data