Black Screen App
The use case is to black out one screen while playing a video on the other. Run it, move it to the desired screen, and press f to toggle fullscreen. This was produced by chatgpt using the following prompt and worked first time:
Simple app in pyside6 that displays a black window, and goes fullscreen with pressing a key like f. The aim is to be able to black out one screen while the machine is playing on the other, such as playing a movie on a TV from a laptop.
#!/usr/bin/env/python
import sys
from PySide6.QtWidgets import QApplication, QWidget
from PySide6.QtGui import QKeyEvent, QPalette, QColor
from PySide6.QtCore import Qt
class BlackoutWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Blackout Screen")
self.setAutoFillBackground(True)
palette = self.palette()
palette.setColor(QPalette.Window, QColor("black"))
self.setPalette(palette)
self.fullscreen = False
self.showNormal()
self.resize(800, 600) # Default size
def keyPressEvent(self, event: QKeyEvent):
if event.key() == Qt.Key_F:
self.toggle_fullscreen()
elif event.key() == Qt.Key_Escape:
self.close()
def toggle_fullscreen(self):
if self.fullscreen:
self.showNormal()
self.fullscreen = False
else:
self.showFullScreen()
self.fullscreen = True
if __name__ == "__main__":
app = QApplication(sys.argv)
window = BlackoutWindow()
window.show()
sys.exit(app.exec())