Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在连接到Raspberry Pi的显示器上显示GUI?_Python_Raspberry Pi_Pyqt5 - Fatal编程技术网

Python 如何在连接到Raspberry Pi的显示器上显示GUI?

Python 如何在连接到Raspberry Pi的显示器上显示GUI?,python,raspberry-pi,pyqt5,Python,Raspberry Pi,Pyqt5,编辑:用“导出显示=:0”解决 原始问题: 我有一个连接到我的树莓皮3B+。它工作正常,我可以看到Raspberry的桌面 我在我的PC上通过我的Raspberry上的SSH在VSCode上工作。因此,当我启动python脚本时,它会在Raspberry上运行,但终端输出是在我的PC上的VSCode中。到目前为止还不错 我现在用PyQt5编程了一个简单的GUI,并希望在Raspberry的显示器上显示它。但我总是犯错误: qt.qpa.screen: QXcbConnection: Could

编辑:用“导出显示=:0”解决

原始问题:

我有一个连接到我的树莓皮3B+。它工作正常,我可以看到Raspberry的桌面

我在我的PC上通过我的Raspberry上的SSH在VSCode上工作。因此,当我启动python脚本时,它会在Raspberry上运行,但终端输出是在我的PC上的VSCode中。到目前为止还不错

我现在用PyQt5编程了一个简单的GUI,并希望在Raspberry的显示器上显示它。但我总是犯错误:

qt.qpa.screen: QXcbConnection: Could not connect to display. Could not connect to any X display.
所有的解决方案都是如何解决隧道问题,Raspberry可以在我的PC显示器上显示GUI,但我想让它只显示在Raspberry的显示器上,否则工作正常

有什么建议吗

这是我的代码,在raspberry over ssh上执行:

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys


class MyWindow(QMainWindow):
    def __init__(self):
        super(MyWindow,self).__init__()
        self.initUI()

    def button_clicked(self):
        self.label.setText("you pressed the button")
        self.update()

    def initUI(self):
        self.setGeometry(0, 0, 100, 100)
        self.setWindowTitle("Tech With Tim")

        self.label = QtWidgets.QLabel(self)
        self.label.setText("my first label!")
        self.label.move(50,50)

        self.b1 = QtWidgets.QPushButton(self)
        self.b1.setText("click me!")
        self.b1.clicked.connect(self.button_clicked)

    def update(self):
        self.label.adjustSize()


def window():
    app = QApplication(sys.argv)
    win = MyWindow()
    win.show()
    sys.exit(app.exec_())

window()

从远程SSH运行时,必须设置
显示
环境,该环境通常为
:0.0
(从X启动时,通常在虚拟终端上自动设置)。在运行脚本之前,请尝试使用
export DISPLAY=:0.0
。就是这样!谢谢!请不要编辑添加“已解决”备注的问题。正如(你应该遵循的)所指出的:“[StackOverflow i]不是一个讨论论坛。”。您可以添加自己的答案,或者等待其他人给出答案,感谢本例中的评论,有人发现了答案。请注意,在本例中,这实际上是另一个问题的重复问题:(这也意味着它可能会被关闭)。