-1

I dont't know why I can't get the value of the scale and why I get this error message. Can anyone help me?

from tkinter import *
Op = Tk()
def sb():
    print (Voboll1)




Oboll=Label(Op, text='BOLL')
Oboll.grid(row=1,column=0)

Voboll1 = StringVar()

# Création d'un widget Scale
Oboll1= Scale(Op,from_=-0.2,to=0.2,resolution=0.01,orient=HORIZONTAL,\
length=235,width=20,tickinterval=20,variable=Voboll1,command=sb)
Oboll1.grid(row=1,column=1)


Op.mainloop()

The error message:

TypeError: sb() takes no arguments (1 given)
finefoot
  • 9,914
  • 7
  • 59
  • 102

1 Answers1

2

From the documentation:

Scale widget command option: this procedure will be passed one argument, the new scale value.

src: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/scale.html

Thus the command parameter automatically passes a value to the procedure you call, in this case sb(). However, your sb definition takes no parameters, thus a conflict and the error occurs.

Since it seems you want to use the Voboll1 value for the Scale, include Voboll1 as a parameter to your sb procedure.

def sb(Voboll1):
   ...

Should clear the error.

  • Confusingly named, perhaps. It seems to me that the call should be something more like `Scale(..., command=lambda s: print(s))`, but in any case shadowing the nonlocal `Voboll1` with a parameter named `Voboll1` bends the mind a little bit. – Adam Smith Jul 12 '17 at 23:02