![](/img/trans.png)
[英]How do I receive the updated time every time it is called in this function?
[英]How do I print value of tk slider every time it is updated?
我的python程序中有一個tk滑塊,每當我移動它時,我都試圖獲得它的值。 程序確實讀出了滑塊的初始值,但僅此而已。 這是我的代碼:
valuelist[50, 100, 150, 200]
class MainApp(Frame):
def valuecheck(val, self, scale):
scalepic = scale
print scalepic.get()
def createControls(self):
scalepic = Scale(self, from_=min(valuelist), to=max(valuelist), resolution = 25, orient=HORIZONTAL)
scalepic.set(100)
scalepic.configure(command = self.valuecheck(val, scalepic))
scalepic.pack()
def __init__(self, parent):
Frame.__init__(self, parent, width = 800, height = 600)
self.pack()
self.createControls()
我嘗試將其添加到valuecheck的正文中:
newval = min(valueList, key=lambda x:abs(x-float(val)))
scalepic.set(newval)
print newval
並且在定義scalepic時擺脫了分辨率選項。 我還嘗試將scalepic.get()作為val的參數傳遞。 我還嘗試在valuecheck中刪除val作為參數,還應該嘗試什么?
不要將功能分配給command
。 使用lambda
。
scalepic.configure(command = lambda :self.valuecheck(scalepic))
還要編輯您的函數:
def valuecheck(self, scale):
因為不需要val
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.