Using tkinter with Catalina, how to avoid deprecation warning?

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.)


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!