Skip to content Skip to sidebar Skip to footer

Trying To Get The Value From A Tkinter Scale And Put It Into A Label

I have a small Python program that takes the value of a Tkinter scale and puts it into a label. #!/usr/bin/python from Tkinter import * class App: strval = StringVar() d

Solution 1:

That happens because you are creating the StringVar before creating the Tk root element. If you move the statement root = Tk() before the definition of the class, you'll see how it works as expected.

However, the ideal solution would be write it in a way that you don't depend on the order to make it work, so I'd suggest you to create the StringVar in the constructor:

classApp:def__init__(self,master):
        frame = Frame(master)
        frame.pack()
        self.strval = StringVar(frame)
        # ...

Post a Comment for "Trying To Get The Value From A Tkinter Scale And Put It Into A Label"