Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TKinter缩放和GUI更新_Python_Tkinter - Fatal编程技术网

Python TKinter缩放和GUI更新

Python TKinter缩放和GUI更新,python,tkinter,Python,Tkinter,我试图使用tkinter创建一个GUI,其中包含缩放按钮等。 现在,我收集了这些天平。我知道可以使用scale.set() 现在,我有一个表单列表,例如[[1,2,3,4,5],[5,4,3,2,1],[3,3,3,3] 我想检查列表中的每个元素(例如[1,2,3,4,5]),并用这个元素的值更新量表(这也是一个列表) 我也是 def runMotion(): #r=3 for n in range(len(list)): print(list[n])

我试图使用tkinter创建一个GUI,其中包含缩放按钮等。 现在,我收集了这些天平。我知道可以使用
scale.set()
现在,我有一个表单列表,例如
[[1,2,3,4,5],[5,4,3,2,1],[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]。刻度

问题是除了最后一个(在我们的例子中是[3,3,3,3,3] 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()

谢谢。我会阅读你的解决方案来理解它。只有一个问题:runMotion是否被递归调用?我问这个问题是因为在我编写的程序中,在下一个版本中,我将无限期地运行它,我不想冻结GUI或耗尽资源。技术上,runMotion被安排在事件堆栈上。Th事件循环(mainloop)经常检查事件堆栈,如果计划运行某个事件,它将运行该事件。这就是root.after(5000…)命令正在执行--每次runMotion完成时放置一个事件。这样做的效果是在不阻止GUI中的用户输入的情况下执行GUI更新,并允许GUI在下一个runMotion事件之前进行可视化更新。