Why am I not able to call python Tkinter in MATLAB?

8 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2021 年 4 月 21 日
編集済み: MathWorks Support Team 2021 年 4 月 22 日
I receive the following error when I run "py.tkinter.Tk()" though I installed the tcl files from activestate.
Error using __init__ (line 2270)
Python Error: TclError: Can't find a usable init.tcl in the following
directories:
  C:/Users/sji/AppData/Local/Programs/Python/Python38/lib/tcl8.6
  C:/MATLAB/R2021a/bin/lib/tcl8.6 C:/MATLAB/R2021a/lib/tcl8.6
  C:/MATLAB/R2021a/bin/library C:/MATLAB/R2021a/library
  C:/MATLAB/R2021a/tcl8.6.9/library C:/MATLAB/tcl8.6.9/library
This probably means that Tcl wasn't installed properly.

採用された回答

MathWorks Support Team
MathWorks Support Team 2024 年 12 月 4 日
編集済み: MathWorks Support Team 2021 年 4 月 22 日
Looking at the Python source code Modules\_tkinter.c, TCL uses hard coded location of tcl_library_path to find its initialization files which doesn't work when Python is loaded by MATLAB.  
Here is an workaround:
>> setenv('TCL_LIBRARY', 'C:\Users\sji\AppData\Local\Programs\Python\Python38\tcl\tcl8.6')
>> setenv('TK_LIBRARY', 'C:\Users\sji\AppData\Local\Programs\Python\Python38\tcl\tk8.6')
>> py.tkinter.Tk
Run these commands every time you run MATLAB. Alternatively, place the commands in a MATLAB startup script.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by