Checkbox To Determine If An Action Is Completed Or Not
I have a list of dictionaries of clients in a format like this: dict_list = [{'Name of Business' : 'Amazon', 'Contact Name' : 'Jeff Bezos', 'Email' : 'Jeff@Amazon.com'}, {'Name of
Solution 1:
First, you should iterate directly over the list rather than using a counter and a while loop:
for client in dict_list:
currentClient = Label(text='Client: ' + client['Client']).grid(row=[i], column=1)
...
Second, if you do x=Label(...).grid(...)
, x
will always be None. Best practice is to use two different statements. In this case the point is moot since you never use currentClient
, but you should get in the habit of always separating them. Group your widget creation together, and your layout together, and your GUI will be much easier to manage:
for client in dict_list:
clientLabel = Label(...)
contactLabel = Label(...)
emailLabel = Label(...)
clientLabel.grid(...)
contactLabel.grid(...)
emailLabel.grid(...)
Third -- and this is the answer to your question -- you can create an instance of IntVar
for each checkbutton, and store them either in a separate data structure or right along with your data. For example, to store them by business name you might do it like this:
cbVars = {}
for client in dict_list:
...
bizname = client["Business Name"]
cbVars[bizname] = IntVar()
cb = Checkbutton(..., onvalue=1, offvalue = 0, variable = cbVars[bizname])
...
Post a Comment for "Checkbox To Determine If An Action Is Completed Or Not"