Tk's default Toplevel - counterintuitive

bowman bowman at montana.com
Fri Aug 20 00:17:19 EDT 1999


Chad Netzer wrote:
> 
> PS.  What is the way to register a callback so that you can intercept the
> window manager's request to destroy a window?  Then you could just bind
> the sys.exit call to this on the Tk object...

def main():
	global top
	top = Tk()
	top.withdraw()
	
	mb = buildMenubar()
	mb.entryconfigure(2, activebackground='red')
	myTop = Toplevel(menu=mb)
	myTop.bind('<Destroy>', dying)

	
def dying(event) :
	print 'Toplevel is getting destroyed'
	top.quit()


The above snippet is a little ugly, but it works. Otherwise, if you kill
the visible window with the system box, the top process keeps on
chugging along. I like the Toplevel's menu setup rather than using
Menubutton's and the deprecated (atleast in the Tcl/Tk world)
tk_menuBar.




-- 
Bear Technology  Making Montana safe for Grizzlies

http://people.montana.com/~bowman/




More information about the Python-list mailing list