'How to run python/Tkinter in a VNC conected to a EC2 instance

I was able to connect to the EC2 instance through TigerVNC, but when running python applications that have Tkinter I get the following error:

Tkinter: no display name and no $DISPLAY environment

Then I ran the following command:

export DISPLAY=:1

So I get the following error when running python code:

Couldn't connect to display ":1"

Any suggestion to solve this?



Solution 1:[1]

I created a new EC2 instance and when installing lxde I chose gdm3 as the default display manager option.. so I was able to run xcalc with DISPLAY=:1.0.. But when running the application that contained Tkinter I had the same problem.. The solution was the following command:

export DISPLAY=:1.0; xhost +

So xhost helps you use the computing power of another machine like an EC2 instance to run a graph and display it on the client screen.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 searcher__dm01