LoginSignup
4
1

More than 5 years have passed since last update.

Tkinterを使うときの環境変数

Posted at

Windows環境で、Tkinterを使おうとするとTcl/Tkライブラリが見つからず、このようなエラーがでた時の対応方法。

    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: Can't find a usable tk.tcl in the following directories: 
    {C:\Python27\tcl\tk8.5} C:/Python27/tcl/tcl8.5/tk8.5 C:/lib/tk8.5 C:/library

TCL_LIBRARYと、TK_LIBRARYの環境変数を指定すると動くようになる。
複数のバージョンのPythonやTcl/Tkが入っていて、環境変数をいじりたく無い時はプログラムの先頭でos.environを直接いじっても上手く行く。

サンプルプログラム

# -*- coding: utf-8 -*-
__author__ = 'Natsutani'

import os
from matplotlib.pyplot import *;

def main():
    # 環境変数の設定
    os.environ['TCL_LIBRARY'] = 'C:/Python32/tcl/tcl8.5'
    os.environ['TK_LIBRARY'] = 'C:/Python32/tcl/tk8.5'

    x = (5,11,3,5)
    y = (3,5,3,5)
    scatter(x,y)
    show()

if __name__ == "__main__":
    main()
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1