[PYTHON] An error that does not work as expected when calling the tkinter module in a text editor

Calling the tkinter module doesn't work as expected ...

As a Python engineer, I wanted to be involved in a lot of development in the future, so I decided to start developing Python for the first time, and based on the reference book, I decided to create an application using the tkinter module. But an error occurs and the window does not open ...

Since I've been exposed to Puby and PHP so far, I'm used to facing errors, so I decided to check the details of the errors immediately. The following content was written in a part of the error statement.

If this fails your Python may not be configured for Tk

But IDLE works as expected, but why doesn't it work with a text editor?

In other words, I thought that ** my PC (Mac) does not have Tcl / Tk built-in **.

PATH problem?

$ ls -al /usr/bin/wish*
$ which wish
$ echo 'puts $tcl_version;exit 0' | wish
$ echo $PATH

Try this in the terminal and the output result will be below!

ChisakinoMacBook-Pro:~ Chisaki$ ls -al /usr/bin/wish*
lrwxr-xr-x  1 root  wheel    7  9 21  2018 /usr/bin/wish -> wish8.5
-r-xr-xr-x  1 root  wheel  127  8 18  2018 /usr/bin/wish8.5
ChisakinoMacBook-Pro:~ Chisaki$ which wish
/usr/bin/wish
ChisakinoMacBook-Pro:~ Chisaki$ echo 'puts $tcl_version;exit 0' | wish
8.5
ChisakinoMacBook-Pro:~ Chisaki$ echo $PATH
/Users/Chisaki/.pyenv/shims:/Users/Chisaki/.pyenv/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/Users/Chisaki/.pyenv/shims:/Library/Frameworks/Python.framework/Versions/3.8/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/opt/[email protected]/bin:/Users/Chisaki/.rbenv/shims:/usr/local/opt/[email protected]/bin:/usr/local/opt/[email protected]/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Older version of Tcl / Tk was enabled Σ (・ □ ・ ;)

From the output result, I thought about ** uninstalling Python anew so that the latest tcl / tk is installed and installing it again **.

$ pyenv uninstall 3.7.6
$ env \
  PATH="$(brew --prefix tcl-tk)/bin:$PATH" \
  LDFLAGS="-L$(brew --prefix tcl-tk)/lib" \
  CPPFLAGS="-I$(brew --prefix tcl-tk)/include" \
  PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
  CFLAGS="-I$(brew --prefix tcl-tk)/include" \
  PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' --with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6'" \
  pyenv install 3.7.6
$ pyenv global 3.7.6

When I executed these in order from the top, I was able to confirm that it works by calling the tkinter module with a text editor ^ _ ^

Recommended Posts

An error that does not work as expected when calling the tkinter module in a text editor
Check items when the imported python module does not work as expected
When incrementing the value of a key that does not exist
A story that didn't work when I tried to log in with the Python requests module
Check points when MIDI does not work in a program using SDL_mixer
The eval () function that calculates a string as an expression in python
In the Chainer tutorial, I get an error when importing a package. (mock)
Patch when full text search does not work in GAE / Python local environment
[Pyhton] I want to solve the problem that tkinter does not work on MacOS11
A story that an error occurred when PyInstaller was used in a program that uses googleapiclient
Error display (unresolved import'hoge') when importing self-made module does not disappear in VS Code
Command when ACPI shutdown does not work in VirtualBox
The story that yapf did not work in vscode
Check the argument type annotation when executing a function in Python and make an error
About the matter that nosetests does not pass when __init__.py is created in the project directory
The story that `while queue` did not work in python
The story that a hash error came out when using Pipenv
The story of the release work of the application that Google does not tell
The story that 2D list replacement did not work in python
Get the formula in an excel file as a string in Python
When the program pip installed on Mac / Marvericks does not work
I get an error when I put a Python plugin in Visual Studio Code under the pyenv environment
What to do if you get the error RuntimeError: Python is not installed as a framework when trying to use matplitlib and pylab in Python 3.3
If you want a singleton in python, think of the module as a singleton
python> does not include the letters mm> if "mm" not in text: / print "not including mm"
The module that should have been installed with pip does not run
When the Linux command $ yum -y install gives an error (yum: command not found)
[https proxy with squid] Eliminate the error when accessing the web server that does not chain the intermediate CA certificate.
[Windows] The problem that an error occurs when opening a file other than CP932 (Shift-JIS) encoded in Python has been solved for the time being.