samedi 15 mai 2021

How can i sum the values of checkboxes in python if they were made using a loop?

Recently i have made a code which adds checkbuttons based on the items i put in the list.Items in the list consist of String connected to integer, so one window with checkboxes would look like this: London(3.40) New York(2.20) California(1.2) etc.What i would like to do now is make a button that when clicked sums the integers from the checkboxes. Note: I have two lists, one list is list of integers Example = [1.2,3.4,2.45,2.4] and other list is list of items Items = ["London","New York","California","Toronto"], after they have been connected with a loop in another list which consists of Items(Value) i made a loop that generates checkbuttons based on amount of Items from that connected list.

I do not know how to implement get() function in a loop so that when i click few checkboxes it sums them and prints them through the button Sum. In which ways can this be done?

Example of a code:

Values = [1.2,3.4,5.4]
Items = ["London","Lisbon","Athens"]

Connect = ['%.2f', % i for i in Values]

while i != len(Connect):
    Items[i] = Items[i]+"(" + Connect[i] + ")"
    i = i+ 1

for j in range(len(Values)):
    items = tkinter.Checkbutton(window, text=Items[j], onvalue=1, offvalue=0)

From now on i need to make a function that will sum checked checkboxes and print the sum once button Sum is clicked. Thank you for your help in forward!




Aucun commentaire:

Enregistrer un commentaire