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

Mike Fletcher mfletch at tpresence.com
Sun Oct 29 21:42:59 EST 2000


Third time for this question, still no (as in nada, zip, zero, zilch)
responses. I'm beginning to suspect that, like me, everyone has already
moved to wxPython :o) .

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"?  Even if you don't know, feel free to tell me you love
Tkinter, or I'll just have to conclude it's an unloved orphan ;o) and stop
trying to get it working with micro-threads.  (Hey, we could even drop Togl
support for PyOpenGL and save a few more headaches ;o)  ).

Meritocracy requires speech, and copious amounts thereof.  Start your
campaigns now!
Mike(y)

-----Original Message-----
From: Mike Fletcher [mailto:mfletch at tpresence.com]
Sent: Wednesday, October 25, 2000 4:53 PM
To: Python List (E-mail)
Subject: Retry: Help: Tkinter mainloop rewrite, when do we want to
exit/wh ere is the "app.OnExit" callback?


Seems this didn't go through (or the subject wasn't clear enough).  I've
been asked how to run Tkinter under micro-threads.  I only use wxPython, so
I'm not really sure how to write the mainloop substitute for Tkinter.  For
wxPython I use the OnExit handler for the wxApp to kill the mainloop
micro-thread.  Could some Tkinter guru suggest the correct test/event for
when to shut down the mainloop?

Side note: are all the mouse interactions under Tkinter atomic C functions?
For instance, dragging or resizing the window stops all other micro-threads
until the drag/resize stops.

Any pointers appreciated,
Mike

8<_________________ Tkinter test ____________
import uthread9
from Tkinter import *
from _tkinter import dooneevent
def go():
	print 'starting TK'
	global root
	root=Tk()
	while 1: # should use some TK-specific mechanism for determining
when the root is closed, don't know what...
		if not dooneevent( tkinter.DONT_WAIT ):
			uthread9.wait( 0.01 )
	print 'somehow exited loop'

def yo( finishedThread ):
	i=0
	for x in range(1000000):
		if x % 10000 == 0:
			print '.',
	finishedThread.exit()
	print 'exited mainloop'

uthread9.new(yo, uthread9.new(go) )
uthread9.run()

8<______________ wxPython mainloop (from larger codebase) _______
	def MainLoop(self):
		# This outer loop determines when to exit the application,
for
		# this example we let the main frame reset this flag when it
		# closes.
		self.mainloopThread = uthread9.new( self.__mainLoop )
		uthread9.new( self.StartMUTech )
		if not uthread9.microThreadsRunning():
			uthread9.run()
	def __mainLoop( self ):
		try:
			while 1:
				# This inner loop will process any GUI
events until there
				# are no more waiting.
				while self.Pending():
					uthread9.atomic( self.Dispatch )

				# Send idle events to idle handlers.  You
may want to throtle
				# this back a bit so there is not too much
CPU time spent in
				# the idle handlers.  For this example, I'll
just snooze a
				# little...
				uthread9.switchContext()
				uthread9.atomic( self.ProcessIdle )
				uthread9.wait( 0.01 ) # hack!
		except:
			traceback.print_exc()
	def OnExit( self, event ):
		print 'closing mutech'
		self.MUTech.close()
		print 'exiting'
		event.Skip()
		if self.mainloopThread:
			self.mainloopThread.exit()



__________________________________
 Mike C. Fletcher
 Designer, VR Plumber
 http://members.home.com/mcfletch

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




More information about the Python-list mailing list