Python Forum
Find Checkbutton State
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find Checkbutton State
#1
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 Clicked
Error:
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'
Reply


Messages In This Thread
Find Checkbutton State - by PEGylated_User - Oct-21-2020, 02:58 PM
RE: Find Checkbutton State - by deanhystad - Oct-21-2020, 03:29 PM
RE: Find Checkbutton State - by joe_momma - Oct-21-2020, 10:30 PM
RE: Find Checkbutton State - by Larz60+ - Oct-23-2020, 12:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Checkbutton writing selection to file blakefindlay 1 2,137 Jan-28-2021, 01:56 PM
Last Post: deanhystad
Question [Tkinter] Checkbutton clicks events does not update visually. nicolaask 1 3,031 Dec-20-2020, 06:11 PM
Last Post: nicolaask
  [Tkinter] How to insert 'Checkbutton' to 'Treeview' and associate each item? water 2 13,302 Dec-19-2020, 05:24 PM
Last Post: water
  [tkinter] not getting checkbutton value when clicked OogieM 5 6,189 Sep-20-2020, 04:49 PM
Last Post: deanhystad
  [Tkinter] ttk.Checkbutton set on/off ifigazsi 5 10,593 Apr-04-2020, 07:34 PM
Last Post: deanhystad
  tkinter checkbutton if checked MC2020 2 6,042 Jan-21-2020, 07:08 PM
Last Post: joe_momma
  [Tkinter] Can't seem to get the current state of a checkbutton. p_hobbs 6 3,391 Nov-07-2019, 11:38 PM
Last Post: p_hobbs
  [Tkinter] Create a set of checkbutton widgets and refer to every one of them individually? Mariano 1 2,722 Apr-11-2019, 06:20 PM
Last Post: woooee
  doing something after been checked a checkbutton gray 1 4,317 Feb-18-2017, 05:11 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020