python - 如何在 Python 服务器版本上使用 Tkinter?
问题描述
我尝试在 Python 服务器版本上使用 Tkinter。(Linux)但我失败了。如何在 Python 服务器版本上使用 tkinter?
-----------------------------------------------------------------------------
import tkinter ; window = tkinter.Tk()
-----------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-16-c9e945514158> in <module>
1 import tkinter
----> 2 window = tkinter.Tk()
~/anaconda3/lib/python3.7/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use)
2021 baseName = baseName + ext
2022 interactive = 0
-> 2023 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
2024 if useTk:
2025 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
解决方案
将 DISPLAY 环境变量设置为:0.0
一般来说,您可以在终端中使用以下命令执行此操作:
export DISPLAY=:0.0
或者在python中:
import os
os.environ["DISPLAY"] = ":0.0"
推荐阅读
- encryption - 流密码的工作原理
- c# - 在 C# 中解析没有年份的闰年总是失败
- python - 在 Google App Engine 上部署 Flask 应用程序
- java - 如何在 AWS Lambda 函数中设置 java.util.logging.config.file?
- java - 如何在 selenium java 中滚动 iframe 内的 PDF
- c++ - 通过指针访问数组
- string - 如何从其他方法访问字符串
- database - 数据库关系不在 BCNF 中的最小证据是什么?
- android - Android检测人开始游戏
- sql - 如何修复错误插入值 ASP 到 SQL“将 nvarchar 数据类型转换为日期时间数据类型导致值超出范围...”