Skip to content

Instantly share code, notes, and snippets.

@zed
Last active November 25, 2019 23:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zed/62227e5e360fd2a5316c74af9497f42b to your computer and use it in GitHub Desktop.
Save zed/62227e5e360fd2a5316c74af9497f42b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""Draw text in the center of the screen."""
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QApplication, QLabel
app = QApplication(sys.argv)
w = QLabel()
w.setWindowFlags(Qt.FramelessWindowHint)
w.setAttribute(Qt.WA_TranslucentBackground)
w.setText("Draw text...")
w.setFont(QFont("Times", 25, QFont.Normal))
# w.move(x, y) or center
w.adjustSize() # update w.rect() now
w.move(app.desktop().screen().rect().center() - w.rect().center())
w.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment