Question

So I'm doing a simple program that basically makes a scale/slidebar on the screen. When I run the application the scale shows up and works, but it doesn't print the values to the console(terminal). Instead it prints error messages

import Tkinter
class App:
    def __init__(self,parent):
        self.scale = Tkinter.Scale(parent,from_ = 0, to = 100, command = self.getVal)
        self.scale.pack()
    def getVal(self):
        amount = self.scale.get()
        print str(amount)
root = Tkinter.Tk()

app = App(root)
root.mainloop()

This is the error message:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", line 1403, in __call__
    return self.func(*args)
TypeError: getVal() takes exactly 1 argument (2 given)

I'm pretty new at Tkinter so I'm a little lost.

EDIT: Python 2.5 guys. sorry.

Was it helpful?

Solution

The command callback receives a new scale value as an argument. Change getVal definition to:

def getVal(self, newscale):
    print newscale
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top