我知道这是一个非常古老的问题,但我对 Gtk+3 也有同样的问题,并且使用 Gtk.events_pending() 没有效果,所以我采取了不同的路线。
Basically, I just put a button to manually clear the splash screen, which I've seen plenty of commercial apps do. Then I call window.present() on the splash screen after creating the main window to keep the splash screen in front. This seems to be just the pause Gtk+3 needs to actually show the splash screen content before showing the main window opening behind it.
class splashScreen():
def __init__(self):
#I happen to be using Glade
self.gladefile = "VideoDatabase.glade"
self.builder = Gtk.Builder()
self.builder.add_from_file(self.gladefile)
self.builder.connect_signals(self)
self.window = self.builder.get_object("splashscreen")
#I give my splashscreen an "OK" button
#This is not an uncommon UI approach
self.button = self.builder.get_object("button")
#Button cannot be clicked at first
self.button.set_sensitive(False)
#Clicking the button will destroy the window
self.button.connect("clicked", self.clear)
self.window.show_all()
#Also tried putting this here to no avail
while Gtk.events_pending():
Gtk.main_iteration()
def clear(self, widget):
self.window.destroy()
class mainWindow():
def __init__(self, splash):
self.splash = splash
#Tons of slow initialization steps
#That take several seconds
#Finally, make the splashscreen OK button clickable
#You could probably call splash.window.destroy() here too
self.splash.button.set_sensitive(True)
if __name__ == "__main__":
splScr = splashScreen()
#Leaving this here, has no noticeable effect
while Gtk.events_pending():
Gtk.main_iteration()
#I pass the splashscreen as an argument to my main window
main = mainWindow(splScr)
#And make the splashscreen present to make sure it is in front
#otherwise it gets hidden
splScr.window.present()
Gtk.main()