[英]How set the initial value for a tkinter Scale widget in Python?
I want to initialize the value of a Scale
widget to 2
. 我想将Scale
小部件的值初始化为2
。 How can I do this? 我怎样才能做到这一点? Because I used a grid, .set
won't work properly. 由于使用网格, .set
将无法正常工作。
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)
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
; .grid()
返回None
; calling it after Scale like you've done won't return a Scale object like you would expect, it will return a Nonetype. 像您一样在Scale之后调用它不会像您期望的那样返回Scale对象,它将返回一个Nonetype。 Implementing this small change should allow you to use .set
on whatever variable you store the Scale object in. ( yourScale
in this example) 实施此小更改,应允许您在存储Scale对象的任何变量上使用.set
。(在此示例中为yourScale
)
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. 顺便说一句:您可能要删除问题中的set
标记: set
引用数据结构,而不是Tkinter的set函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.