I'm trying to create a simple .bin editor, but I can into a problem very early on. I can't figure out how to get the value of each checkbutton. As you see, I am trying to keep the code as condensed as possible by using a class to create all the checkbuttons.
Right now all I am trying to do is get the "saveSave" function to print out if the box is checked or not so that I can later use it in an if...else statement.
try: #Python 2 imports
from Tkinter import *
import ttk
import tkFileDialog as filedialog
except ImportError: #Python 3 imports
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
def openSave():
file = filedialog.askopenfilename()
def saveSave():
print MaxMP.get()
class CB(Frame):
def __init__(self, parent=None, cheater=""):
Frame.__init__(self, parent)
self.var = BooleanVar()
rawr = Checkbutton(self, text=cheater, variable=self.var, onvalue=1, offvalue=0, bg="white", command=self.saveSave)
rawr.pack()
self.grid(sticky='w', columnspan=2)
pmdxse = Tk()
pmdxse.title("Project Mirai DX Save Editor")
pmdxse.configure(bg="white", padx=10, pady=10)
pmdxse.resizable(width=False, height=False)
Button(pmdxse, text="Open", command=openSave).grid(row=0, column=0)
Button(pmdxse, text="Save", command=saveSave).grid(row=0, column=1)
MaxMP = CB(pmdxse, 'Max MP')
MaxSnacks = CB(pmdxse, 'Max Snacks')
MaxHighscore = CB(pmdxse, 'Max Highscore')
MaxPerfentage = CB(pmdxse, 'Max Percentage')
MaxCombo = CB(pmdxse, 'Max Combo')
UnlockSongs = CB(pmdxse, 'Unlock all Songs')
UnlockHard = CB(pmdxse, 'Unlock Hard/Super Hard Modes')
UnlockItems = CB(pmdxse, 'Unlock all Items in the Shop')
UnlockOutfits = CB(pmdxse, 'Unlock all Outfits')
UnlockStamps = CB(pmdxse, 'Unlock all 115 Stamps')
UnlockProfileOptions = CB(pmdxse, 'Unlock all Profile Options')
MaxRank = CB(pmdxse, 'Set each song to \"Prefect\" rank')
BuyItems = CB(pmdxse, 'Buy all Items')
BuyOutfits = CB(pmdxse, 'Buy all Outfits')
pmdxse.mainloop()