[英]TKinter scales and GUI update
我正在嘗試使用tkinter創建一個包含刻度按鈕等的GUI。現在,我有了這個刻度集合。 而且我知道可以使用scale.set()
來更新scale.set()
現在,我有了[[1,2,3,4,5],[5,4,3,2,1],[3,3,3,3,3]]
。
我想遍歷列表的每個元素(例如[1,2,3,4,5]),並使用該元素的值(也是列表)更新比例尺
所以我做
def runMotion():
#r=3
for n in range(len(list)):
print(list[n])
for count in range(5):
print(list[n][count])
motorList[count].scale.set(list[n][count])
#motorList[count].moveTo(list[n][count])
time.sleep(5)
這里motorList是一個類的數組,每個類都有一個小數位,因此motorList[count].scale
問題是,除了最后一個(在我們的情況下[3,3,3,3,3],GUI)(刻度)沒有更新,GUI在執行時被凍結,並且只有最后一個“運動”反映在屏幕上。標度值。
我是python的初學者,特別是做GUI的人,在這里請多指教
問題是您正在使用“ for”循環,該循環阻止了TK事件循環。 這意味着事情是由您的程序計算的,但是GUI不會更新。 請嘗試以下操作:
list = [[1,2,3,4,5],[5,4,3,2,1],[3,3,3,3,3]]
def runMotion(count):
if len(list) == count:
return
print(list[count])
for index,n in enumerate(list[count]):
print(index,n)
motorList[index].set(n)
#motorList[count].moveTo(list[n][count])
root.after(5000, lambda c=count+1: runMotion(c))
root = Tk()
motorList = []
for i in range(1,6):
s = Scale(root, from_=1, to=5)
s.grid(row=i-1)
motorList.append(s)
runMotion(0)
root.mainloop()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.