Oct-21-2020, 02:58 PM
I am creating a form to have a user input information for making labels. One of the issues I am running into is that I cant figure out how to call for the check button state after the finished button is clicked.
from tkinter import *
from tkinter import ttk
class Stability_Label_Creator():
def __init__(self, master):
self.notebook = ttk.Notebook(master)
self.notebook.pack()
# 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)
FormulationVar = BooleanVar()
Formulation = 'Formulation' + str(x)
Formulation = ttk.Checkbutton(self.formulations, text = '', variable = FormulationVar, onvalue = True, offvalue = False)
Formulation.grid(row = x, column = 2)
FormulationVar.set(False)
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')
def Next(self):
# Moves to next tab in notebook
self.notebook.select(1)
# print(self.formulations.Formulation01.state())
def Back(self):
# Returns to first tab in notebook
self.notebook.select(0)
def print(self):
print('Formulation Name: {}'.format(self.FormulationName01.get()))
print('Formulation Selected: {}'.format(self.FormulationVar01.get()))
def main():
mainwindow = Tk()
mainwindow.title('Stability Label Creator')
app = Stability_Label_Creator(mainwindow)
mainwindow.mainloop()
if __name__ == "__main__": main()I some how need to find all the children text boxes on the Formulations frame in the note and determine which ones are checked.Output:Finished Button ClickedError:Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\02260235\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "c:/Users/02260235/Downloads/Test App/TkinterTest.py", line 79, in Finished
for cb in self.formulations.findChild(self):
AttributeError: 'Frame' object has no attribute 'findChild'
