This article is to make tkinter (a Python binding to the Tk GUI toolkit) work using pyenv on macOS

Steps

install tcl-tk with homebrew

brew install tcl-tk

add the following to .bashrc or .bash_profile and then reload shell

export PATH="$(brew --prefix tcl-tk)/bin:$PATH"

if you have the Python version already installed with pyenv then uninstall it with:

pyenv uninstall <your python version>

set environment variable that will be used by python-build. in shell run (NOTE: in future use tck-tk version that actually installed with Homebrew. At the moment of posting 8.6 was the actual)

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'"

finally reinstall Python

pyenv install <version>

Test

python -m tkinter -c "tkinter._test()"

you should see a test window