TrevorAppleton
Posts: 74
Joined: Wed May 30, 2012 7:26 pm
Contact: Website

Running Tkinter as Root

Thu May 02, 2013 1:27 pm

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.
Check out my blog post for Raspberry Pi and Python tutorials.

http://trevorappleton.blogspot.co.uk/

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Running Tkinter as Root

Thu May 02, 2013 1:43 pm

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?
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

TrevorAppleton
Posts: 74
Joined: Wed May 30, 2012 7:26 pm
Contact: Website

Re: Running Tkinter as Root

Thu May 02, 2013 2:05 pm

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.
Check out my blog post for Raspberry Pi and Python tutorials.

http://trevorappleton.blogspot.co.uk/

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Running Tkinter as Root

Thu May 02, 2013 2:27 pm

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!)
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Return to “Python”