tkinter.TclError: no display name and no $DISPLAY environment variable python

tkinter.TclError: no display name and no $DISPLAY environment variable python

我想使用 ssh 在远程系统中执行我的 python 文件。我将文件导出到远程系统。

示例文件如下:

import os
import time
import pymsgbox

pymsgbox.alert('Hi Afreeth ', 'Welcome')
if 'DISPLAY' not in os.environ: 
    pass

我想从我的系统使用 ssh 执行它,它应该显示在远程系统中。 但是失败了

我得到的错误:

Traceback (most recent call last):
  File "cd1.py", line 5, in <module>
  File "pymsgbox/__init__.py", line 100, in alert
  File "pymsgbox/__init__.py", line 156, in _buttonbox
  File "tkinter/__init__.py", line 1871, in __init__
_tkinter.TclError: no display name and no $DISPLAY environment variable
[12113] Failed to execute script myprogram

如何解决。我在堆栈上找到了一些答案,但并没有解决我的问题。如果我去远程系统中执行它,它就可以工作。但是当我从我的系统执行时,它失败了。如何解决。

找到答案: 我只需要在他们的 ssh 会话中 运行 export DISPLAY=:0 和程序 运行 将 运行 在远程显示器上。一个简单的例子:

paulsteven@smackcoders:~$ ssh afreeth@his_ipaddress
afreeth@smackcoders:~$ export DISPLAY=:0
afreeth@smackcoders:~$ firefox
Firefox is now running on afreeth's display.