tkinter.TclError:没有显示名称,也没有 $DISPLAY 环境变量 python [英] tkinter.TclError: no display name and no $DISPLAY environment variable python

查看:103
本文介绍了tkinter.TclError:没有显示名称,也没有 $DISPLAY 环境变量 python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to execute my python file in a remote system using ssh. I exported the file to the remote system.

这是示例文件:

import os
import time
import pymsgbox

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

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

I want to execute it using ssh from my system and it should display in the remote system. But it fails

我得到的错误:

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

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

How to fix it. I found some answers on stack but it doesn't solve me. If i go and execute it in the remote system, it works. But when i execute from my system,it fails. How to fix it.

推荐答案

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

Found the Answer: I just need to run export DISPLAY=:0 in their ssh session and programs run will run on the remote display. A quick example:

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

这篇关于tkinter.TclError:没有显示名称,也没有 $DISPLAY 环境变量 python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆