How set the initial value for a tkinter Scale widget in Python?

1.2k views Asked by At

I want to initialize the value of a Scale widget to 2. How can I do this? Because I used a grid, .set won't work properly.

Here is my code:

Scale(self, command=self.onMove, movesvariable=self.var, from_=1, to=10,orient=HORIZONTAL,length=500,tickinterval=0.5, resolution=0.1, cursor = 'hand2 ').grid(columnspan ='200',rowspan = '4',sticky= W)
1

There are 1 answers

2
maccartm On

Change this to two lines:

yourScale = Scale(self, command=self.onMove, movesvariable=self.var, from_=1, to=10,orient=HORIZONTAL,length=500,tickinterval=0.5, resolution=0.1, cursor = 'hand2 ')
yourScale.grid(columnspan ='200',rowspan = '4',sticky= W)

.grid() returns None; calling it after Scale like you've done won't return a Scale object like you would expect, it will return a Nonetype. Implementing this small change should allow you to use .set on whatever variable you store the Scale object in. (yourScale in this example)

As an aside: You might want to remove the set tag in your question: set references a data structure, not the set function from Tkinter.