[Tkinter-discuss] Iterate Scale widgets
rkundu at ouray.cudenver.edu
rkundu at ouray.cudenver.edu
Fri Jun 30 20:00:13 CEST 2006
The problem with the following program is I am not able to get values
corresponding to each scale widgets. I tried initially storing the
scale widget names in a list and then get the values but did not work.
So, I borrowed the trace variable part of the script from some internet
source. In the program below all the scale widgets created are having
the same variable var, how do I change the variable names
automatically or is there any other way to retrieve the values of
scales? Any advice will be appreciated.
Thank you,
Reema
from Tkinter import*
import sys, Tkinter, types, copy
root = Tk()
i = 1
k = 5
var = Tkinter.DoubleVar()
oldvalue = var.get()
def callback(*args):
global oldvalue
#An exclamation point tells var that what follows is a Python
statement, not a var command.
if var.get() != oldvalue:
oldvalue = var.get()
print var.get()
var.trace_variable("w", callback)
while i<=k:
j=1
var1 = var + i
while j<=k:
Scale(root, from_ = 0.0, to = 1.0, resolution = 0.1, variable =
var, orient = 'horizontal').grid(row=i,column=j)
j=j+1
i=i+1
root.mainloop()
More information about the Tkinter-discuss
mailing list