0

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)
finefoot
  • 9,914
  • 7
  • 59
  • 102
jiabo zhou
  • 11
  • 3
  • _"because I use a grid, .set won't word [sic] properly"_. The proper solution is to move the call to `.grid` on a separate line. There's simply no advantage to doing it all in one line. – Bryan Oakley Jun 17 '15 at 16:55
  • i have fixed this problem, but when i enlarge the widget, it wont fix the size of it, Do you have any good solutions to this problem? – jiabo zhou Jun 18 '15 at 03:41

1 Answers1

1

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.

maccartm
  • 2,035
  • 14
  • 23
  • i have fixed this problem, but when i enlarge the widget, it wont fix the size of it, Do you have any good solutions to this problem? – jiabo zhou Jun 18 '15 at 03:41
  • Do you mean the scale doesn't get larger to accommodate for the enlarged widget, or it **does** get larger and you don't want it to? – maccartm Jun 18 '15 at 12:12