tkinter through VNC without physical display

python, python-3.x, raspberry-pi, tkinter, vnc

Solution

I asked this question on RaspberryPi Stack Exchange site, and @hildred had a beautiful solution for this:

Write these few lines to `etc/sudoers`*:

Defaults    env_reset
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Defaults    env_keep += "DISPLAY"
Defaults    env_keep += "XAUTHORITY"

And these few lines to `~/.bashrc`:

if [ -z "$XAUTHORITY" ]; then
    if [ -e $HOME/.Xauthority ]; then
        export XAUTHORITY=$HOME/.Xauthority;
    fi;
fi

**On a Raspbian this will be `etc/sudoers.d/README` for example*

Problem

My setup is: - a Raspberry Pi, running the latest Raspbian (fully updated), a self-compiled Python 3.3.3 - a Mac running Mavericks (10.9) I'm AFP-ed, SSH-ed and VNC-ed to my RPi, and I can run all the command-line scripts I wrote, and also I can open any installed GUI applications, however, when I want to run a tkinter-based GUI app, to control some hardwares connected to the GPIO, I'm having this error message: ``` Client is not authorized to connect to ServerTraceback (most recent call last): ... _tkinter.TclError: couldn't connect to display ":1" ``` My guess is, that this is related to the fact, that there is no physical display attached to the RPi, although I don't know how to solve this situation. Thanks in advance!

Original source