SETUP
I have a python3 application that creates a gui using tkinter. It runs on a Raspberry Pi 4 running Ubuntu 21.10. I'm connected using a remote desktop with the xrdp client. I successfully connect to the Ubuntu desktop, but I can't see desktop icons.
PROBLEM
When I launch the application with root privileges, tkinter gets confused on the display and fails to create the GUI.
sudo python3 /home/ubuntu/Robotics/QuadrupedRobot/StanfordQuadruped/calibrate_tool.py
When I run the application as user, tkinter is able to create the GUI, but now the application does not have permission to interface with root drivers
python3 /home/ubuntu/Robotics/QuadrupedRobot/StanfordQuadruped/calibrate_tool.py
QUESTION
Is there a way to make tkinter work with root permissions on remote desktop, or to write on root files without giving root permission to the full application?
Is there a something I'm doing wrong with the setup?
SOLUTION
This is an X Windows security issue preventing the sudo user accessing the display created by the logged on user. If you're not worried about security on your local network then running the command 'xhost +' will disable all security on the X Windows Display and allow the sudo user to access the display.
pi@pi4desktop:~ $ xhost +
access control disabled, clients can connect from any host
Then you should be able to run your tkinter application using sudo.