Putty: _tkinter.TclError: 没有显示名称,也没有 diplay 环境变量 [英] Putty: _tkinter.TclError: no display name and no diplay environment variable

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

问题描述

链接问题:Mac OS X:_tkinter.TclError:没有显示名称和 $DISPLAY 环境变量

上面有同样的问题,但答案不适用于我.

The above has the same issue but the answer to that doesn't apply to me.

a.py

from Tkinter import * 

root = Tk() 
canvas = Canvas(bg='white', width = 200, height = 200) 
canvas.pack() 

canvas.create_line(0, 0, 199, 199, fill="blue", width = 5) 
canvas.create_line(0, 199, 199, 0, fill="blue", width = 5) 

canvas.update() 
canvas.postscript(file = "x.ps") 

root.mainloop() 

a.py 在远程服务器上

a.py is on a remote server

当我通过 VNC 连接到服务器并运行它时,这工作正常.

This works fine when I connect to a server via VNC and run it.

但是当我通过 Windows 上的 Putty 连接到服务器并运行它时,它给了我没有显示名称和显示环境变量"

But when I connect to a server via Putty on windows and run it, it gives me "no display name and no diplay environment variable"

1) 是否可以通过 Putty 运行它?

1) Is it possible to run this through Putty?

2) python 是否可以知道连接是否是通过 putty 建立的,并且可能会引发我自己的错误而不是 TclError?

2) Can python know if a connection is made through putty and maybe raise my own error instead of TclError?

推荐答案

你需要在你的 windows 机器上运行一个 X 服务器,然后在你登录之前在你的 putty 会话中启用 X11 转发(请参阅连接/SSH/X11 属性PuTTY 中的页面).过去,我使用过免费的 Xming 和不免费的 eXceed.一旦您在实际查看的计算机上拥有 X 服务器并通过 ssh 链接转发 X 连接,它将在远程计算机上设置 DISPLAY 环境变量,以便 X 客户端可以与显示服务器通信.否则,如果没有 DISPLAY 设置,Tk 将引发错误 - 正如您所看到的.

You need to run an X server on your windows machine and then enable X11 forwarding in your putty session before you log in (see the Connection / SSH / X11 property page in PuTTY). In the past I've used Xming which is free and eXceed which was not. Once you have an X server on the machine you actually are looking at and forward the X connection over the ssh link, it will setup the DISPLAY environment variable on the remote machine so that X clients can communicate back to the display server. Otherwise, without a DISPLAY setup Tk will raise an error - as you are seeing.

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

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