Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
PythonGTK图像,多次更改图像后始终没有图像_Python_Image_Gtk_Pygtk - Fatal编程技术网

PythonGTK图像,多次更改图像后始终没有图像

PythonGTK图像,多次更改图像后始终没有图像,python,image,gtk,pygtk,Python,Image,Gtk,Pygtk,我在窗口中有一个Gtk.Image小部件,它必须在一段时间后更改图像。 它在下面的函数线程中运行 def dinChangeBg(self,_Timing): tm.sleep(int(_Timing)) ## Verifica se a janela ainda existe if not(self.Runing): thread.exit() bg = "image/background"+str(

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

    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))
线程调用是:

_thread.start_new_thread(dinChangeBg,(60,)) 
一段时间后,图像不再改变,图像消失, 打印将继续显示图像位置(如果存在)


有人知道这个错误吗?

您不能从另一个线程调用GTK+函数。您的线程必须告诉GTK+线程创建pixbuf和更改图像;你能说会道。或者,如果这是一个足够简单的动画,您可以完全放弃第二个线程,请使用GLib.timeout\u add在超时时运行代码。

尝试后,Gtk.Window不会显示,就像将打开阴影一样,总线不显示任何内容,我启动了GLib.timeout\u add,然后执行GLib.idle\u adddinChangeBg,60,是一个很好的开始,但窗口不显示我有一个while循环和时间。在线程上睡眠,它会中断一个程序。我换了线,现在可以了。谢谢