Python GTK图像,更改图像多次后不断获取任何图像

时间:2017-01-18 14:06:13

标签: python image gtk pygtk

我在窗口中有一个Gtk.Image小部件,它必须在一段时间后更改图像。 它运行在

下面的函数线程中
param (
    [string]$BambooPath = ""
)

$RemoteWebPath = 'C:\DestFolder'
Copy-Item -Path $BambooPath -Destination $RemoteWebPath -Recurse

线程调用是:

    def dinChangeBg(self,_Timing):
        tm.sleep(int(_Timing))

##      Verifica se a janela ainda existe
        if not(self.Runing):
            thread.exit()

        bg = "image/background"+str(self.bgIndex)+".jpg"

        if not (os.path.isfile(bg)):
            print(bg,"bg inesistente")
            self.bgIndex = 1

            bg = "image/background"+str(self.bgIndex)+".jpg"

        if(os.path.isfile(bg)):
            print("new bac", bg)

            pbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(bg, self.Window.get_size()[0],self.Window.get_size()[1], preserve_aspect_ratio=False)
            self.image.clear()
            self.image.set_from_pixbuf(pbuf)
            self.bgIndex += 1


        self.dinChangeBg(int(_Timing))

经过一段时间后,图像没有变化,图像消失了, 如果存在,打印将继续显示图像位置。

有人知道错误吗?

1 个答案:

答案 0 :(得分:1)

您无法从其他线程调用GTK +函数。你的线程必须告诉GTK +线程两者创建pixbuf 更改图像;你用GLib.idle_add()讲述。或者,如果这是一个足够简单的动画,您可以完全放弃第二个线程,请使用GLib.timeout_add()在超时时运行代码。