EDIT: Solved with "export DISPLAY=:0"
Original Problem:
I have a Display connected to my Raspberry Pi 3B+. It's working fine and I can see Raspberry's desktop.
I work on my PC on VSCode via SSH on my Raspberry. So when I start a python script, it runs on the Raspberry, but the terminal outputs are in VSCode on my PC. So far so good.
I programmed now a simple GUI with PyQt5 and want to display it on the Raspberry's display. But I always get the error:
qt.qpa.screen: QXcbConnection: Could not connect to display. Could not connect to any X display.
All the solutions out there are how to solve the tunneling, that the Raspberry can display the GUI on my PC monitor, but I want to have it just on the Raspberry's display which is working fine otherwise.
Any suggestions?
This is my Code, executed on the 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()