如何自动刷新 Gtk.Image 以从同一 URL 获取新帧?图像 now.jpeg 是每秒 1 帧,当加载 Python 脚本时,它只显示第一帧而不是更新的图像。
import os
import urllib2
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf
def quit_event(widget, event):
os.remove(imgname)
Gtk.main_quit()
imgname = 'now.jpeg'
url = 'http://192.168.1.11/'+imgname
response = urllib2.urlopen(url)
with open(imgname, 'wb') as img:
img.write(response.read())
image = Gtk.Image()
pb = Pixbuf.new_from_file(imgname)
image.set_from_pixbuf(pb)
window = Gtk.Window()
window.connect('delete-event', quit_event)
window.add(image)
window.show_all()
Gtk.main()