0

I've tried both of the syntaxes I've found in scouring the Web for the answer to this, but neither one works for me - both complain about my use of the NoneType object, yet the objects seem clearly defined in the code. Sample code below:

import Tkinter as tk

class App:

    def __init__(self, my_dlg_bx):
        my_dlg_bx.title("My Dialog Box")

        def react_to_ckbx_1_chg():
            if value_from_ckbx_1.get():
                print "Checkbox 1 got checked"
                if value_from_ckbx_2.get():
                    print "and Checkbox 2 is already checked"
                    print "so this should enable Checkbox 3"
                    ckbx_3["state"] = tk.NORMAL # TypeError: 'NoneType' object does not support item assignment
            else:
                print "Checkbox 1 got UNchecked"
                print "so this should DISable Checkbox 3"
                ckbx_3.config(state = tk.DISABLED) # AttributeError: 'NoneType' object has no attribute 'config'

        def react_to_ckbx_2_chg():
            if value_from_ckbx_2.get():
                print "Checkbox 2 got checked"
                if value_from_ckbx_1.get():
                    print "and Checkbox 1 is already checked"
                    print "so this should enable Checkbox 3"
                    ckbx_3.config(state = tk.NORMAL) # AttributeError: 'NoneType' object has no attribute 'config'
            else:
                print "Checkbox 2 got UNchecked"
                print "so this should DISable Checkbox 3"
                ckbx_3["state"] = tk.DISABLED # TypeError: 'NoneType' object does not support item assignment

        def react_to_ckbx_3_chg():
            if value_from_ckbx_3.get():
                print "Checkbox 3 got checked"
            else:
                print "Checkbox 3 got UNchecked"

        value_from_ckbx_1 = tk.BooleanVar()
        ckbx_1 = tk.Checkbutton( my_dlg_bx,
                                 command     = react_to_ckbx_1_chg,
                                 offvalue    = False,
                                 onvalue     = True,
                                 text        = "This is Checkbox 1",
                                 variable    = value_from_ckbx_1,
                               ).pack(anchor = tk.W)

        value_from_ckbx_2 = tk.BooleanVar()
        ckbx_2 = tk.Checkbutton( my_dlg_bx,
                                 command     = react_to_ckbx_2_chg,
                                 offvalue    = False,
                                 onvalue     = True,
                                 text        = "This is Checkbox 2",
                                 variable    = value_from_ckbx_2,
                               ).pack(anchor = tk.W)

        value_from_ckbx_3 = tk.BooleanVar()
        ckbx_3 = tk.Checkbutton( my_dlg_bx,
                                 command     = react_to_ckbx_3_chg,
                                 offvalue    = False,
                                 onvalue     = True,
                                 state       = tk.DISABLED,
                                 text        = "MUST CHECK BOTH to activate 3",
                                 variable    = value_from_ckbx_3,
                               ).pack(anchor = tk.W)

if __name__ == "__main__":
    my_dlg_bx = tk.Tk()
    app = App(my_dlg_bx)
    my_dlg_bx.mainloop()

0 Answers0