[英]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.