What to do if you get an error like this because the Tcl / Tk library is not found when you try to use Tkinter in a Windows environment.
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
If you specify TCL_LIBRARY and TK_LIBRARY environment variables, it will work. If you have multiple versions of Python or Tcl / Tk and you don't want to mess with environment variables, you can mess with os.environ directly at the beginning of the program.
Sample program
# -*- coding: utf-8 -*-
__author__ = 'Natsutani'
import os
from matplotlib.pyplot import *;
def main():
#Setting environment variables
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()
Recommended Posts