在连接显示器的无头 Linux 上运行 GUI

问题描述 投票:0回答:1

我正在研究 RPI 零 W 并连接 7 英寸显示屏。我想使用 Tkinter for Python 为其开发一个 GUI 应用程序。我想将其用于我自己开发的 PC 统计监视器,所以我想要一个较小的占用空间,并且我认为使用更好的 PI 会有点矫枉过正,并且会达不到目的(但如果需要的话,我愿意改变这一点) ).

我正在运行无头 Raspberry 操作系统,我可以看到显示屏本身显示终端,现在我只想将 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"

我该如何解决这个问题?

python linux tkinter raspberry-pi operating-system
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.