Page 1 of 1

Running Tkinter as Root

Posted: Thu May 02, 2013 1:27 pm
by TrevorAppleton
Hi,

I am trying to run a Python program which has a GUI I have written to interact with the GPIO. The GUI runs ok but when I run it as Root i.e.

sudo python nameofprogram.py

I get an error message stating that

Client is not authorized to connet to ServerTraceback (most recent call last)
...
...
...
tkinter.TclError: couldn't connect to display ":0.0"

Any ideas how to run Tkinter as root? The program runs fine as my normal user but needs to be root to access the GPIO.

Re: Running Tkinter as Root

Posted: Thu May 02, 2013 1:43 pm
by DeeJay
Just to say that I can't answer your question authoritatively, but that I have also had difficulty with this and posted some of my findings in this thread - http://www.raspberrypi.org/phpBB3/viewt ... 60#p338360

I too would welcome a clear explanation if one exists. Is there a difference in behaviour between running the graphics 'locally' on the RPi as opposed to running a remote Xserver and getting access via ssh with Xwindows port-forwarding?

Re: Running Tkinter as Root

Posted: Thu May 02, 2013 2:05 pm
by TrevorAppleton
Thanks DeeJay I really struggled finding an answer for this. A few minutes after posting in the forum I found your original post. I am about to try the Root Terminal method, however there must be a proper way to do this.

Re: Running Tkinter as Root

Posted: Thu May 02, 2013 2:27 pm
by DeeJay
Further to our own problems of running our own code...

It seems that the IDLE and IDLE3 IDEs are themselves applications which rely on the Tkinter gui toolkit.

I can run IDLE with root privs by invoking it from a gksu session.

But I have completely failed to get IDLE3 to run in a headless scenario, whether in userland or with elevated privs.

(I know that one response is that python3 is bleeding-edge and can/should be ignored, but if the tool is shipped as part of the recommended distribution then my purist approach is that it should 'just work' straight out of the box!)