[Tutor] Exiting a PyGTK main loop

Bart Cramer bart.cramer at gmail.com
Sat Sep 20 00:16:52 CEST 2008


Dear all,

I am a bit stuck in a small project, trying to quit a PyGTK program.
Here are some relevant snippets:

	def init_gui (self) :
		
		self.window = gtk.Window (gtk.WINDOW_TOPLEVEL)
		
		self.window.connect ("delete_event", self.delete_event)
		self.window.connect ("destroy", self.destroy)

	def delete_event(self, widget, event, data=None) :
		return False

	def destroy(self, widget, data=None) :
		gtk.main_quit()

Seems pretty standard so far... Now, I want the following: if a
certain condition has been met (categories run out...), the program
should quit, exit status 0.

		if len(categories) == 0 :
			gtk.main_quit()

The error message I get is the following:

RuntimeError: called outside of a mainloop

So I suppose that I should send a signal or event to the main loop,
which will terminate it by some magic on its own. But how do I do
that?

Thanks in advance for your time!

Bart.


More information about the Tutor mailing list