Putty: _tkinter.TclError: no display name and no diplay environment variable

对着背影说爱祢 提交于 2019-12-11 22:22:40

问题


Linked Question: Mac OS X: _tkinter.TclError: no display name and no $DISPLAY environment variable

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 is on a remote server

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

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) Is it possible to run this through Putty?

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


回答1:


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.



来源:https://stackoverflow.com/questions/19409201/putty-tkinter-tclerror-no-display-name-and-no-diplay-environment-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!