简体   繁体   English

Python Tkinter软件包无法正常运行

[英]Python tkinter package not functioning properly

I'm just starting with tkinter, not even running or preparing complex GUI apps, I have used this simple commands on other servers and it has worked perfectly, so the problem is probably in my installation. 我只是从tkinter开始,甚至没有运行或准备复杂的GUI应用程序,而是在其他服务器上使用了此简单命令,并且效果很好,因此问题可能出在我的安装中。

My Linux version is 18.04 my python version is 3.6.5 .I have tried connecting from ssh, tried connecting from windows putty ( itś a remote server). 我的Linux版本是18.04,我的python版本是3.6.5。我尝试从ssh连接,尝试从Windows putty(远程服务器)连接。

this is the code I try to execute: 这是我尝试执行的代码:

from tkinter import * 
potato = Tk()
potato.mainloop()

This is the error I get: 这是我得到的错误:

---------------------------------------------------------------------------
TclError                                  Traceback (most recent call last)
<ipython-input-1-1a8e1fdc2509> in <module>()
      1 from tkinter import *
----> 2 potato = Tk()
      3 potato.mainloop()

/usr/lib/python3.6/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use)
   2018                 baseName = baseName + ext
   2019         interactive = 0
-> 2020         self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
   2021         if useTk:
   2022             self._loadtk()



TclError: no display name and no $DISPLAY environment variable

I'm kind of a noob, so please tell me any missing information you might need. 我有点菜鸟,所以请告诉我您可能需要的任何缺失信息。

Your code works properly don't worry about it. 您的代码正常工作,不用担心。

In this case the error you are getting ( no display name and no $DISPLAY environment variable ) is related to your SSH connection due to that the server is not able to find a display where to render your program. 在这种情况下,由于服务器无法找到在何处呈现您的程序的显示,您得到的错误( no display name and no $DISPLAY environment variable )与您的SSH连接有关。

If you want to use PuTTY and view the tkinter app in your windows machine (run a X server) you will need to specify that in the PuTTY configuration beforehand. 如果要使用PuTTY,并在Windows机器(运行X服务器)中查看tkinter应用程序,则需要事先在PuTTY配置中指定它。 In order to do that you just have to enable the X11 forwarding (in Connection > SSH > X11 > Enable X11 forwarding). 为此,您只需要启用X11转发(在“连接”>“ SSH”>“ X11”>“启用X11转发”中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM