ich würde gerne die 'Decision'-Checkbuttons ausgrauen, wenn die oberste Checkbox des zugehörigen Frames deaktiviert wird. Das ganze soll natürlich reversibel vom Status der der oberen Checkbox abhängig sein. Ich denke mal es sollte mit 'command' und 'state' funktionieren, zB unter Nutzung der Funktion 'chg_moduleState' ?
Code: Alles auswählen
from Tkinter import *
from functools import partial
prioKey = 'prio'
def exDict(dict_):
dict_ = dict_.copy()
for key in dict_.keys():
if not isinstance(dict_[key], dict):
del dict_[key]
return dict_
def prioList(dict_):
for key in dict_.keys():
if int(dict_[key][prioKey]) == 0:
del dict_[key]
list = sorted(dict_, key = lambda k: int(dict_[k][prioKey]))
return list
def initWidgets(moduleTop):
myDict = {'Frame_1': {'Decision_1': {'prio': '0'}, 'prio': '0', 'Decision_2': {'prio': '0'}, 'Decision_3': {'prio': '2'}},
'Frame_2': {'Decision_1': {'prio': '0'}, 'prio': '0', 'Decision_2': {'prio': '0'}, 'Decision_3': {'prio': '2'}}}
def chg_moduleState(moduleFrame):
if int_var.get() == 1:
moduleFrame.moduleStateVar = ACTIVE
else:
moduleFrame.moduleStateVar = DISABLED
for i, (moduleKey, moduleVal) in enumerate(myDict.iteritems()):
setattr(moduleTop, moduleKey, LabelFrame(moduleTop, text = moduleKey, padx = 5, pady = 5))
moduleFrame = getattr(moduleTop, moduleKey)
moduleFrame.grid(sticky = 'NESW', row = 0, column = i)
int_var = IntVar()
int_var.set(int(moduleVal[prioKey]))
setattr(moduleFrame, moduleKey, int_var)
checkBtn = Checkbutton(moduleFrame, variable = int_var)#, command = None)
checkBtn.grid(sticky = W, row = 0, column = 0, columnspan = 1)
module = exDict(myDict[moduleKey])
for j, (testKey, testVal) in enumerate(module.iteritems()):
int_var = IntVar()
int_var.set(int(testVal[prioKey]))
setattr(moduleFrame, testKey, int_var)
checkBtn = Checkbutton(moduleFrame, text = testKey, variable = int_var)#, state = ACTIVE)
checkBtn.grid(sticky = W, row = j + 1, column = 0, columnspan = 1)
root = Tk()
initWidgets(root)
root.mainloop()