Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.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在给定时间后实时更改图像 我现在有一个ListBox,它有几十个图像的路径,当选择列表框中的元素时,图像将显示在GUI的中间。_Python_Tkinter - Fatal编程技术网

Python Tkinter在给定时间后实时更改图像 我现在有一个ListBox,它有几十个图像的路径,当选择列表框中的元素时,图像将显示在GUI的中间。

Python Tkinter在给定时间后实时更改图像 我现在有一个ListBox,它有几十个图像的路径,当选择列表框中的元素时,图像将显示在GUI的中间。,python,tkinter,Python,Tkinter,我的第三张图片有两种不同的外观,所以我写道: #Third image elif (self.index==3): start = clock() self.label.configure(image=self.photo2[1])#first image if (start>2): self.label.configure(image=self.phot

我的第三张图片有两种不同的外观,所以我写道:

        #Third image
        elif (self.index==3):
            start = clock()
            self.label.configure(image=self.photo2[1])#first image
            if (start>2):
                self.label.configure(image=self.photo2[2])#second image
现在,当用户单击第三个元素时,它将首先显示第一个图像,然后如果在两秒钟后重新单击,它将显示第二个图像,这样就可以了


然而,我想要的是,我的第三个图像在两秒钟后自动更改,而无需重新单击。有没有办法更新tkinter直播的图像,或者我可以采取什么方法?

这是一种常见的模式。您应该使用
Tk.after
来运行更改图像的函数,然后安排下一次更改

def change_image(label, imagelist, nextindex):
    label.configure(image=imagelist[nextindex])
    root.after(2000, lambda: change_image(label, imagelist, (nextindex+1) % len(imagelist)))
然后给它打一次电话,让它永远做自己的事

root = Tk()
setup_your_stuff()
change_image(root.label, root.photo2, 0)

这是一种常见的模式。您应该使用
Tk.after
来运行更改图像的函数,然后安排下一次更改

def change_image(label, imagelist, nextindex):
    label.configure(image=imagelist[nextindex])
    root.after(2000, lambda: change_image(label, imagelist, (nextindex+1) % len(imagelist)))
然后给它打一次电话,让它永远做自己的事

root = Tk()
setup_your_stuff()
change_image(root.label, root.photo2, 0)

有些事情我需要改变,但tk.after正是我想要的,谢谢!有些事情我需要改变,但tk.after正是我想要的,谢谢!