Skip to content

Instantly share code, notes, and snippets.

@DataSolveProblems
Last active March 25, 2020 14:26
Show Gist options
  • Save DataSolveProblems/1ced8b3a9856f929f3d746c8bf7aa462 to your computer and use it in GitHub Desktop.
Save DataSolveProblems/1ced8b3a9856f929f3d746c8bf7aa462 to your computer and use it in GitHub Desktop.
import sys
from PyQt5.QtWidgets import QWidget, QDesktopWidget, QApplication
class Demo(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('Center the app')
self.center()
self.show()
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
if __name__ == '__main__':
app = QApplication(sys.argv)
demo = Demo()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment