Reputation: 53
I have a Gtk.Image widget in a window, and it must change image after a time. it run in a thread of function below
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))
the thread call is:
_thread.start_new_thread(dinChangeBg,(60,))
after a time it no change more the image and a image desappears, the print continues to show a image location if it exists .
someone have a idea of the error?
Upvotes: 0
Views: 209
Reputation: 11588
You cannot call GTK+ functions from another thread. Your thread will have to tell the GTK+ thread to both create the pixbuf and change the image; you do the telling with GLib.idle_add()
. Or, if this is an animation that is simple enough that you can forego the second thread entirely, use GLib.timeout_add()
to run the code on a timeout.
Upvotes: 1