9

I want to use the tkinter GUI library with python3 and Catalina 10.15.1, but I get a deprecation warning.

% python3
Python 3.7.4 (default, Oct 26 2019, 09:13:24)
>>> import tkinter
>>> tkinter.Tk()
DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.

I looked at this answer but brew install tcl-tk and brew install python3 but didn't help.

Is there a straightforward way to get tkinter to work, or is a different GUI library the recommended way to go? (I'm a bit worried that if I start installing new Python versions, I'll end up breaking other things.)

4
  • this should be safe to try - the breakage going newer than 3.7.4 should be very manageable and you could pin the brew python3 to 3.7.4 if breakage couldn’t be tested or contained. apple.stackexchange.com/a/315121/5472
    – bmike
    Commented Nov 27, 2019 at 1:53
  • @bmike: I tried that uninstall/reinstall sequence and it didn't help. Commented Nov 27, 2019 at 2:30
  • See this answer: stackoverflow.com/questions/58752385/… seems you need to upgrade to python 3.8
    – Yoan
    Commented Nov 27, 2019 at 14:27
  • 1
    I would suggest using virtenv for your Python apps and use pip to install your needed modules within each virtenv as needed. Also, what Yoan said (or 3.9 even).
    – JGurtz
    Commented Jun 13, 2021 at 8:37

1 Answer 1

3

You may need to run brew install [email protected], which has the description "Python interface to Tcl/Tk".

If you don't want to update Tkinter, it depends on which shell you're using. First, run echo ${SHELL}.

If the response from that command is /bin/zsh or anything else ending is zsh, run the following:

echo 'export TK_SILENCE_DEPRECATION=1' >> ~/.zshrc

There should be no output from that command, but you'll need to restart your terminal window.

If the response from the first command is something ending in bash, you need to run

echo 'export TK_SILENCE_DEPRECATION=1' >> ~/.bash_profile

Which also doesn't have an output, and also requires restarting the terminal window.

Sidenote: if you're running this in a Python script or something that needs to work on other computers, You'll need to add the following to it:

import os
# Set environment variable
os.environ['TK_SILENCE_DEPRECATION'] = 1

Hope this helps!

2
  • pip install tk doesn't actually accomplish anything; it's actually some completely unrelated package pypi.org/project/tk. There're some random websites which suggest this, but in truth it has no effect on tkinter at all. Commented Aug 10, 2021 at 16:27
  • @orthocresol you're right, I should have checked the pip docs before I posted this (tk refers to tensorkit in this case, for some reason). I'll update my answer to reflect this. Commented Aug 12, 2021 at 0:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .