Hi,
I have several tkinter entries created within a loop, where users input numbers.
I wish to create a reset button to set all entries to zero.
On the following code the reset button will just reset the last entry.
How is possible to call each of the entry and set its value to zero ?
Thanks for any help
from Tkinter import *
data = [
('a', 0, 'liters soda'),
('b', 0, 'liters beer'),
('c', 0, 'liters wine')
]
## Create grid, extracting infos from the data array
## Collect the text variables to list for use
def createWidgets(root, clist=[]):
L=0
global c_w
while L < len(data):
cg_w=DoubleVar()
clist.append(cg_w)
l_w=Label(root, text=data[L][2])
l_w.grid(row=L)
c_w=Entry(root, textvariable=cg_w, width=3)
c_w.grid(row=L,column=1)
L+=1
root=Tk()
root.title('Bar')
##
cl=[]
createWidgets(root,cl)
## Example of simple function using values from an edited list (cl)
def Calc():
L=0
v=0
lit=0
for L,v in enumerate(cl):
lit+=v.get()
TotLiters.configure(text='%g' % lit)
def SetToZero():
c_w.delete(0,END)
cg_w=0.0
c_w.insert(END,cg_w)
compute = Button(root, text=' Total liters = ', command=Calc)
compute.grid(row=0,column=3)
reset = Button(root, text=' reset ', command=SetToZero)
reset.grid(row=2,column=3)
TotLiters=Label(root, width=10)
TotLiters.grid(row=0,column=4)
root.mainloop()