pyi_rth__tkinter.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2013-2023, PyInstaller Development Team.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: Apache-2.0
  10. #-----------------------------------------------------------------------------
  11. def _pyi_rthook():
  12. import os
  13. import sys
  14. # The directory names must match TCL_ROOTNAME and TK_ROOTNAME constants defined in `PyInstaller.utils.hooks.tcl_tk`.
  15. tcldir = os.path.join(sys._MEIPASS, '_tcl_data')
  16. tkdir = os.path.join(sys._MEIPASS, '_tk_data')
  17. # Notify "tkinter" of data directories. On macOS, we do not collect data directories if system Tcl/Tk framework is
  18. # used. On other OSes, we always collect them, so their absence is considered an error.
  19. is_darwin = sys.platform == 'darwin'
  20. if os.path.isdir(tcldir):
  21. os.environ["TCL_LIBRARY"] = tcldir
  22. elif not is_darwin:
  23. raise FileNotFoundError('Tcl data directory "%s" not found.' % tcldir)
  24. if os.path.isdir(tkdir):
  25. os.environ["TK_LIBRARY"] = tkdir
  26. elif not is_darwin:
  27. raise FileNotFoundError('Tk data directory "%s" not found.' % tkdir)
  28. _pyi_rthook()
  29. del _pyi_rthook