![](/img/trans.png)
[英]How control the value of a tkinter `Scale` widget depending on the value of another tkinter `Scale` widget in Python?
[英]How set the initial value for a tkinter Scale widget in Python?
我想将Scale
小部件的值初始化为2
。 我怎样才能做到这一点? 由于使用网格, .set
将无法正常工作。
这是我的代码:
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)
将其更改为两行:
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()
返回None
; 像您一样在Scale之后调用它不会像您期望的那样返回Scale对象,它将返回一个Nonetype。 实施此小更改,应允许您在存储Scale对象的任何变量上使用.set
。(在此示例中为yourScale
)
顺便说一句:您可能要删除问题中的set
标记: set
引用数据结构,而不是Tkinter的set函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.