Problem
-
Running a Tkinter-based GUI module remotely on a remote Linux machine through remote SSH setup results in the error:
_tkinter.TclError: no display name and no $DISPLAY environment variable. -
The GUI elements, such as buttons, are not displayed.
Cause
This issue occurs because the DISPLAY environment variable, which instructs where the graphical display should render, is not set in the remote session.
Resolution
The issue can be resolved by properly setting the DISPLAY environment variable using one of the following methods:
-
Code-Based Approach:
Insert the following code in the Python script before initializing Tkinter:
import os os.environ["DISPLAY"] = ":0" -
Configuration-Based Approach:
Configure PyCharm's Run/Debug settings to include the
DISPLAYvariable:- Navigate to Run | Edit Configurations in PyCharm.
- Locate your Python configuration.
- Add an environment variable
DISPLAY=:0
Comments
0 comments
Please sign in to leave a comment.