Shall we declare Tkinter dead? No-one seems interested in it ;o)

Mike Fletcher mfletch at tpresence.com
Mon Oct 30 03:33:34 EST 2000


Re: missing posts...  I posted to Python list (via mailman), as well as to
the Stackless Python list (though didn't expect you to see it there)...
Maybe the PSU has black-listed me again?  Tim and I haven't been feuding
lately, but maybe Guido got ticked off at my Stackless advocacy (long live
Stackless, we'll never give up!)  Maybe I shouldn't have refused to pay
their protection money last time <sigh> cost of doing business I guess :o) .
http://x54.deja.com/[ST_rn=ps]/getdoc.xp?AN=685834954
The first one does appear to have been swallowed up by some monster or
other.  Oh well, here be dragons, (and big constricting snakes :o) )...

Re: everyone moving to wxPython... There's an awful lot of traffic over
there ;o) ...

Re: handlers and such... Thanks (thanks to kistler too).  Here's the revised
version for the curious.  It doesn't provide for nested mainloops, and it
may be a little too aggressive during shutdown (I was getting memory access
errors if I didn't call destroy on the widget when another micro-thread
called exit (instead of it being called as a callback)), but it does seem to
work (at least, with this trivial example).  I did both the <Destroy> event
and the WM_DELETE_WINDOW, if I understand correctly, either would indicate
that the root window is being destroyed.

Thanks for the help, apparently the old maxim "post horrifically overstated
subject lines and you'll garner helpful responses" holds true :o) .  I'll
have to spend some time next weekend seeing how to integrate this into
Tkinter (i.e. allow for replacing the widget's mainloop method with a
micro-threading one, and making the quit method similarly quit the
micro-threaded loop).   Suppose I'll also have to look into the "after"
methods and such-like.  Any other timing/threading issues you know of?

Enjoy yourself,
Mike

8<_______ testtk.py ___________
import uthread9
from _tkinter import dooneevent
from Tkinter import tkinter


class mainloop:
	exitedNormally = 1
	def __init__( self, rootWidget, pollFrequency= 0.001,
exitAllOnFinish=1 ):
		rootWidget.bind( "<Destroy>", self.quit )
		rootWidget.protocol( "WM_DELETE_WINDOW", self.quit )
		self.rootWidget = rootWidget
		uthread9.new(self._mainloop, pollFrequency, exitAllOnFinish)
	def _mainloop( self, pollFrequency= 0.001, exitAllOnFinish=1 ):
		'''The micro-threading main loop, probably the worst example
of tkinter
		programming on the face of the earth :o) '''
		self.__activate__()
		while self.active: # should use some TK-specific mechanism
for determining when the root is closed, don't know what...
			if not uthread9.atomic( dooneevent,
tkinter.DONT_WAIT ):
				uthread9.wait( pollFrequency )
		try:
			self.rootWidget.destroy()
		except:
			pass
		if exitAllOnFinish:
			uthread9.exitAll(1)
	def quit( self, event=None ):
		self.__deactivate__()
		return "break"
	def __activate__(self):
		self.active = 1
	def __deactivate__( self):
		self.active = 0

		

if __name__ == "__main__":
	from Tkinter import Tk
	root=Tk()
	def yo( ):
		uthread9.wait( 4 )
		print 'second thread finished sleeping'
		main.quit()

	main = mainloop(root)
	uthread9.new(yo)
	uthread9.run()


-----Original Message-----
From: Fredrik Lundh [mailto:fredrik at effbot.org]
Sent: Monday, October 30, 2000 2:30 AM
To: python-list at python.org
Subject: Re: Shall we declare Tkinter dead? No-one seems interested in
it ;o)


Mike Fletcher wrote:
> Third time for this question, still no (as in nada, zip, zero, zilch)
> responses.

it's the first time I see your question.  where did you send it?

> I'm beginning to suspect that, like me, everyone has already
> moved to wxPython :o) .

really?

> Can anyone tell me what event to bind in a Tkinter system that says "the
> root window has been closed", or, more precisely, "it's safe to shut down
> the mainloop now"?

install a DELETE_WINDOW handler:

    root.protocol("WM_DELETE_WINDOW", callback)

for more info, see:
http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.h
tm

</F>


-- 
http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list