0

I'm trying to update the value of a Scale widget dynamically so it changes its value to the value of another Scale widget. Just to understand how the Scale.set() method works I've tried something like this:

from Tkinter import *

def sel():
   selection = "Value = " + str(varX.get())
   label.config(text = selection)

def test():
    toScale = varX.get()
    scaleY.set(toScale)   


root = Tk()
varX = DoubleVar()
varY = DoubleVar()

scaleX = Scale(root, variable = varX, command=test)
scaleX.pack(anchor=CENTER)

scaleY = Scale(root, variable = varY)
scaleY.pack()

button = Button(root, text="Get Scale Value")
button.pack(anchor=CENTER)

label = Label(root)
label.pack()

txt = Entry(root)
txt.pack()

root.mainloop()

But when I try to run that I got:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1486, in __call__
    return self.func(*args)
TypeError: test() takes no arguments (1 given)

And when I pass the command keyword argument to the button it works fine. What is the problem here? It's all about the Scale widget and its methods I think. I'm not too comfortable with them and any helps will be appreciated.

finefoot
  • 9,914
  • 7
  • 59
  • 102

1 Answers1

2

Scale sends new value to function

def test(value):
    scaleY.set(value)

I think you can use one variable to get the same result

one_variable = DoubleVar()

scaleX = Scale(root, variable=one_variable)
scaleY = Scale(root, variable=one_variable)
furas
  • 134,197
  • 12
  • 106
  • 148
  • Thanks furas your old answer already worked... Can u give me any guess in this topic ? http://stackoverflow.com/questions/33849512/update-tkinter-widget-scale-from-arduino-ports – Vinicius Biscolla Nov 24 '15 at 17:24