Categories
Development Software

PySimpleGUI (and Tkinter) in pyenv with Homebrew

Create a GUI simply, with PySimpleGUI and Homebrew.

I needed to quickly build a simple GUI for administering systems, and I wanted to try out PySimpleGUI. It sits on top of other packages such as Tkinter and PyQt — which needs to be compiled into Python to use it.

For development, I tend to use pyenv and Docker, where as the latter is also what I use for deployment. On Linux you can tie Docker to X11 fairly easily, but there’s no clear way for tying Docker to OS X’s Aqua, and the closest would be using socat to bridge Docker to X11 under OS X.

Prerequisites

Implementation

Install TCL/TK Headers:

brew install tcl-tk

Compile TCL/TK Headers with the latest version of Python under pyenv:

latestTclTk='8.6'

latestPython=`pyenv install --list | sed -e 's/^[[:space:]]*//' | grep --regexp '^[0-9]\.[0-9][\.0-9]*$' | (gsort --version-sort 2>/dev/null || sort --version-sort) | tail -n 1`

PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I/usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl${latestTclTk} -ltk${latestTclTk}'" pyenv install ${latestPython}

Create a virtual environment and install PySimpleGUI into it:

pyenv ${latestPython} myGUIenv

mkdir --parents --verbose ~/myGUIproject

cd $_

pyenv local myGUIenv

pip install PySimpleGUI

External links

Leave a Reply

Your email address will not be published. Required fields are marked *