0

I have a list of dictionaries in a format like this:

dict_list = [{'Contact Name' : 'Jeff Bezos', 'Email' : 'Jeff@Amazon.com', 'Send' : 0},
 {'Contact Name' : 'Bill Gates', 'Email' : 'Bill@Microsoft.com', 'Send' : 0}]

I currently display each name using Tkinter:

for eachclient in dict_list:
   contactLabel = Label(text='Contact Name: ' + eachclient['Contact Name'])     
   emailLabel = Label(text='Contact Email: ' + eachclient['Email'])

I need a Tkinter checkbox that can modify the value of 'Send' for each entry in dict_list.
I will also add a send button that will send only if the checkbox is checked.
(The send button will call a command like:)

   def buttonCheck():
       for eachclient in dict_list:
           if eachclient 'Send' = 1:
              send the message
           else:
              skip this client 

Is this possible? I greatly appreciate any help I can get!

Shiroslullaby
  • 119
  • 1
  • 2
  • 9

1 Answers1

0

The checkboxes themselves could be part of the for loop, with this at the end:

checkbox = Button(text=str(check), command=checkemail, width=2)
# The str(check) part is for rows.

N.B. The buttons themselves will have to be in a grid, similar to this.

enter image description here

Using the cget method (see this for an explanation, and see this for an example), the function for the checkbox could be like this:

def checkemail(): # Using an example function name
    x = int(checkbox.cget("text")) # Gets the row number (check)
    dict_list[x]['Send'] = 1 # Changes the value of 'Send' for the contact to 1

I hope this is helpful!

Community
  • 1
  • 1
Qwerp-Derp
  • 487
  • 7
  • 20