如何在window.hide&show之后重新显示gtk.Image?

问题描述 投票:0回答:1

正如你可以看到这个例子,如果我们关闭然后再显示包含gtk.Label的窗口 - 标签也显示,但如果窗口包含gtk.Image - 我们看不到它。

import gtk,gobject

def dest(*a):
   print 1
   gobject.timeout_add(1000,dest2) 
#also, why it is impossible to show window again at once it closed?


def dest2(*a):
   print 2
   win.add(child)
   win.show_all()
   shild.queue_draw()
   print 'where is is?'

win = gtk.Window()
win.connect('delete-event', dest)
l = gtk.Label('gtk')

image=gtk.Image()
f=fopen('some_image.png','r')
loader = gtk.PixbufLoader()
loader.write(f.read())
loader.close()
f.close()
image.set_from_pixbuf(loader.get_pixbuf())

child=image
#child=l  #so, if uncomment this string - everything is perfect
win.add(child)
win.show_all()
gtk.main()
python gtk pygtk
1个回答
0
投票

@scythargon

什么是shild.queue_draw()?无论如何:

def dest2(*a):
   print 2
   image.set_from_pixbuf(loader.get_pixbuf())      # <<<---- add this "and your hair will be soft and silky"
   win.add(child)
   win.show_all()
#   shild.queue_draw()
   print 'where is is?'

我的pygtk说:loader = gtk.gdk.PixbufLoader()

#also,为什么一旦它关闭就不可能再次显示窗口?

您可以尝试在dest()中使用“return True”

© www.soinside.com 2019 - 2024. All rights reserved.