python - 在连接了显示器的无头 linux 上运行 GUI
问题描述
我正在开发一个连接 7 英寸显示器的 RPI 零 W。我想用 Tkinter for Python 为它开发一个 GUI 应用程序。我想将它用于我自己开发的 PC 统计监视器,所以我想要一个小的占用空间,我认为像使用更好的 PI 那样使用会是一种矫枉过正并且会破坏目的(但如果需要,我愿意改变它) )。
我正在运行一个无头 Raspberry OS,我可以看到显示器本身显示的终端,现在我只想将 GUI 应用程序覆盖在终端上。我正在无头运行以加快启动速度并降低 CPU 上的资源成本。
#!/usr/bin/env python3
from tkinter import *
import sys
import os
if os.environ.get('DISPLAY','') == '':
print('no display found. Using :0.0')
os.environ.__setitem__('DISPLAY', ':0.0')
root = Tk()
#Creating a Label Widget
myLabel = Label(root, text="Hello World!")
#Shoving it onto screen
myLabel.pack()
root.mainloop()
启动应用程序时,我得到回报:
no display found. Using :0.0
Traceback (most recent call last):
File "./gui_test.py", line 11, in <module>
root = Tk()
File "/usr/lib/python3.7/tkinter/__init__.py", line 2023, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0.0"
我怎样才能解决这个问题?
解决方案
推荐阅读
- node.js - 导入lame后Vscode扩展未运行
- arrays - 如何在颤振飞镖中打破字符串并将其插入列表(数组)
- google-apps-script - 在 Google Apps 脚本中创建插件
- c# - 是否获取组件
() 在 T 扩展类上工作? - arrays - 将一组图像上传到 Firebase 存储
- c# - 如何将当前 var 分配给 else 语句以便能够比较 var 值,然后将其保存以获得结果?
- ios - Flutter iOS 应用程序在启动时显示白屏并在该屏幕上挂断
- google-chrome - Headless Chrome 79 无法从 Windows 上的 Google Fonts 加载字体
- redux - 如何在路由更改后更改 redux 状态
- react-native-android - Expo SDK 需要 Expo 才能运行。看来是本地人