'tkinter misbehave with sudo when remote desktop on Ubuntu 21.10 xrdp

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.

Link to the application

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

Tkinter fails to create GUI

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

Permission denied

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

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source