def __init__(self): assert threading.current_thread() is threading.main_thread() # get_ident() is faster than threading.current_thread(), so that is # used elsewhere in the performance-critical stuff self._main_thread_ident = threading.get_ident() self._init_threads_called = False # tkinter does this :D i have no idea what each argument means self._app = _tkinter.create(None, sys.argv[0], 'Tk', 1, 1, 1, 0, None) self._app.call('wm', 'withdraw', '.') self._app.call('package', 'require', 'Ttk') # when a main-thread-needing function is called from another thread, a # tuple like this is added to this queue: # # (func, args, kwargs, future) # # func is a function that MUST be called from main thread # args and kwargs are arguments for func # future will be set when the function has been called # # the function is called from Tk's event loop self._call_queue = queue.Queue()
def tk_version(): # Returns tk version as a tuple, including micro version import _tkinter tk = _tkinter.create() version_string = tk.call("info", "patchlevel") return tuple(int(x) for x in version_string.split("."))
def create_include_tix(): """ find tixxx.dll and related files, manually see http://www.py2exe.org/index.cgi/TixSetup """ # get tcl/tk install information import tkinter import _tkinter tk = _tkinter.create() # get tcl, tk, tix versions tcl_version = _tkinter.TCL_VERSION tk_version = _tkinter.TK_VERSION tix_version = tk.call('package', 'version', 'Tix') # get tcl and tk library directory # see https://stackoverflow.com/questions/35533803/keyerror-tcl-library-when-i-use-cx-freeze tcl_dir = tk.exprstring('$tcl_library') tk_dir = tk.exprstring('$tk_library') del tkinter, _tkinter print('tcl_version = ', tcl_version) print('tk_version = ', tk_version) print('tix_version = ', tix_version) print('tcl_dir = ', tcl_dir) print('tk_dir = ', tk_dir) includelist = [] # set os.environ, # see https://stackoverflow.com/questions/35533803/keyerror-tcl-library-when-i-use-cx-freeze os.environ['TCL_LIBRARY'] = tcl_dir os.environ['TK_LIBRARY'] = tk_dir # tcl and tk dlls tcldllpath = find_in_pathenv('tcl{}t.dll'.format( tcl_version.replace('.', ''))) if tcldllpath is None: raise 'tcl{xx}t.dll is not found' tkdllpath = find_in_pathenv('tk{}t.dll'.format(tk_version.replace('.', ''))) if tkdllpath is None: raise 'tk{xx}t.dll is not found' # try to find tix directory tix_basename = 'tix{}'.format(tix_version) tix_dir = os.path.join(os.path.dirname(tcl_dir), tix_basename) print('tix_dir = ', tix_dir) if not os.path.isdir(tix_dir): raise 'tix_dir does not exist.' return [str(tcldllpath), str(tkdllpath), (tix_dir, tix_basename)]
def TixInfo(): import Tkinter import _tkinter tk = _tkinter.create() tcl_version = _tkinter.TCL_VERSION tk_version = _tkinter.TK_VERSION tix_version = tk.call("package", "version", "Tix") tcl_dir = tk.call("info", "library") del tk, _tkinter, Tkinter return (tcl_version, tk_version, tix_version, tcl_dir)
def TixInfo(): import Tkinter import _tkinter tk=_tkinter.create() tcl_version=_tkinter.TCL_VERSION tk_version=_tkinter.TK_VERSION tix_version=tk.call("package","version","Tix") tcl_dir=tk.call("info","library") del tk, _tkinter, Tkinter return (tcl_version,tk_version,tix_version,tcl_dir)
def load_Tkinter(finder, module): """the Tkinter module has data files that are required to be loaded so ensure that they are copied into the directory that is expected at runtime.""" import Tkinter import _tkinter tk = _tkinter.create() tclDir = os.path.dirname(tk.call("info", "library")) # on OS X, Tcl and Tk are organized in frameworks, different layout if sys.platform == 'darwin' and tk.call('tk', 'windowingsystem') == 'aqua': tclSourceDir=os.path.join(os.path.split(tclDir)[0], 'Tcl') tkSourceDir = tclSourceDir.replace('Tcl', 'Tk') else: tclSourceDir = os.path.join(tclDir, "tcl%s" % _tkinter.TCL_VERSION) tkSourceDir = os.path.join(tclDir, "tk%s" % _tkinter.TK_VERSION) finder.IncludeFiles(tclSourceDir, "tcl") finder.IncludeFiles(tkSourceDir, "tk")
def load_Tkinter(finder, module): """the Tkinter module has data files that are required to be loaded so ensure that they are copied into the directory that is expected at runtime.""" import Tkinter import _tkinter tk = _tkinter.create() tclDir = os.path.dirname(tk.call("info", "library")) # on OS X, Tcl and Tk are organized in frameworks, different layout if sys.platform == 'darwin' and tk.call('tk', 'windowingsystem') == 'aqua': tclSourceDir = os.path.join(os.path.split(tclDir)[0], 'Tcl') tkSourceDir = tclSourceDir.replace('Tcl', 'Tk') else: tclSourceDir = os.path.join(tclDir, "tcl%s" % _tkinter.TCL_VERSION) tkSourceDir = os.path.join(tclDir, "tk%s" % _tkinter.TK_VERSION) finder.IncludeFiles(tclSourceDir, "tcl") finder.IncludeFiles(tkSourceDir, "tk")
def tk_dirs(mf): '''Tk directories''' if "Tkinter" not in mf.modules: return [] import Tkinter import _tkinter tk = _tkinter.create() tcl_dir = tk.call("info", "library") tcl_src_dir = split(tcl_dir)[0] dirs = [ join(tcl_src_dir, "tcl%s" % _tkinter.TCL_VERSION), join(tcl_src_dir, "tk%s" % _tkinter.TK_VERSION)] del tk, _tkinter, Tkinter return dirs
# This is about all it requires to write a wish shell in Python! import _tkinter import os tk = _tkinter.create(os.environ['DISPLAY'], 'wish', 'Tk', 1) tk.call('update') cmd = '' while 1: if cmd: prompt = '' else: prompt = '% ' try: line = raw_input(prompt) except EOFError: break cmd = cmd + (line + '\n') if tk.getboolean(tk.call('info', 'complete', cmd)): tk.record(line) try: result = tk.call('eval', cmd) except _tkinter.TclError, msg: print 'TclError:', msg else: if result: print result cmd = ''