def cleanup(): from tkinter import _default_root, TclError import tkinter try: if _default_root: _default_root.destroy() except TclError: pass tkinter._default_root = None
def cleanup(): try: from tkinter import _default_root, TclError import tkinter try: if _default_root: _default_root.destroy() except TclError: pass tkinter._default_root = None except SystemError: # If cleanup() is called before pyraf fully loads, we will # see: "SystemError: Parent module 'pyraf' not loaded". In that case, # since nothing was done yet w/ _default_root, we can safely skip this. pass
) except NameError as err: # no __file__, likely running as an egg TOGL_DLL_PATH = "" if not os.path.isdir( TOGL_DLL_PATH ): _log.warning( 'Expected Tk Togl installation in %s', TOGL_DLL_PATH ) _log.info( 'Loading Togl from: %s', TOGL_DLL_PATH ) _default_root.tk.call('lappend', 'auto_path', TOGL_DLL_PATH) try: _default_root.tk.call('package', 'require', 'Togl') _default_root.tk.eval('load {} Togl') except TclError as err: _log.error( """Failure loading Togl package: %s""", err ) if _default_root: _default_root.destroy() raise # This code is needed to avoid faults on sys.exit() # [DAA, Jan 1998], updated by mcfletch 2009 import atexit def cleanup(): try: import tkinter except ImportError: import Tkinter as tkinter try: if tkinter._default_root: tkinter._default_root.destroy() except (TclError,AttributeError): pass tkinter._default_root = None