Oct-21-2020, 10:30 PM
I have seen one way is to create a dictionary and save the name as key and an IntVar as value, the checked box is 1.
here's a rewrite of your code hope it points you on path to success:
here's a rewrite of your code hope it points you on path to success:
from tkinter import * from tkinter import ttk class Stability_Label_Creator(): def __init__(self, master): self.notebook = ttk.Notebook(master) self.notebook.pack() self.checkbuttons= {} # Add tabs to main window self.formulations = ttk.Frame(self.notebook) self.stabilityschedule = ttk.Frame(self.notebook) self.notebook.add(self.formulations, text = 'Formulations') self.notebook.add(self.stabilityschedule, text = 'Stability Schedule') ttk.Label(self.formulations, text = 'Formulation Name').grid(row = 0, column = 3) ttk.Label(self.formulations, text = 'Formulation Lot Number').grid(row = 0, column = 4) for x in range(1, 26): RowLabel = 'RowLabel' + str(x) RowLabel = ttk.Label(self.formulations, text = x) RowLabel.grid(row = x, column = 1) FormulationVar = 'FormulationVar' + str(x) value_= IntVar() self.checkbuttons[FormulationVar]= value_ self._Formulation = 'Formulation' + str(x) self._Formulation = ttk.Checkbutton(self.formulations, text = FormulationVar, variable = value_, ) self._Formulation.grid(row = x, column = 2) FormulationName = 'FormulationName' + str(x) FormulationName = ttk.Entry(self.formulations, width = 30) FormulationName.grid(row = x, column = 3) FormulationLot = 'FormulationLot' + str(x) FormulationLot = ttk.Entry(self.formulations, width = 30) FormulationLot.grid(row = x, column = 4) self.NextButton = ttk.Button(self.formulations, text = 'Next', command = self.Next) self.NextButton.grid(row = 26, column = 4) ttk.Label(self.stabilityschedule, text = 'Time Point').grid(row = 0, column = 2) ttk.Label(self.stabilityschedule, text = 'Storage Conditions').grid(row = 0, column = 3, columnspan = 7) ttk.Label(self.stabilityschedule, text = 'Vials Per Time Point').grid(row = 0, column = 10) self.BackButton = ttk.Button(self.stabilityschedule, text = 'Back', command = self.Back) self.BackButton.grid(row = 26, column = 9) self.FinishedButton = ttk.Button(self.stabilityschedule, text = 'Finished', command = self.Finished) self.FinishedButton.grid(row = 26, column = 10) for x in range(1, 26): TimePointLabel = 'TimePointLabel' + str(x) TimePointLabel = ttk.Label(self.stabilityschedule, text = x) TimePointLabel.grid(row = x, column = 1) TimePoint = 'TimePoint' + str(x) TimePoint = ttk.Entry(self.stabilityschedule, width = 30) TimePoint.grid(row = x, column = 2) VialsPerTimePoint = 'VialsPerTimePoint' + str(x) VialsPerTimePoint = ttk.Entry(self.stabilityschedule, width = 30) VialsPerTimePoint.grid(row = x, column = 10) # Need to get the Check Box Text to be correct. Right now they all say 60C StorCond = ['-20C', '5C', '25C', '30C', '40C', '50C', '60C'] for x in range(1, 26): for y in range(3, 10): # for y in range(3, 10): StorageConditionsVar = 'StorageConditionsVar' + str(StorCond[y-3]) StorageConditionsVar = BooleanVar() StorageConditions = 'StorageConditions' + str(StorCond[y-3]) self.StorageConditions = ttk.Checkbutton(self.stabilityschedule, name = 'storageConditions' + str(StorCond[y-3]) + str(x), text = str(StorCond[y-3]), variable = StorageConditionsVar, onvalue = True, offvalue = False) StorageConditionsVar.set(False) self.StorageConditions.grid(row = x, column = y) # print(self.StorageConditions.state()) def Finished(self): print('Finished Button Clicked') for key,value in self.checkbuttons.items(): if value.get(): print(key) #prints the name of the checked box def Next(self): # Moves to next tab in notebook self.notebook.select(1) def Back(self): # Returns to first tab in notebook self.notebook.select(0) def main(): mainwindow = Tk() mainwindow.title('Stability Label Creator') app = Stability_Label_Creator(mainwindow) mainwindow.mainloop() if __name__ == "__main__": main()