Last active
March 25, 2020 14:26
-
-
Save DataSolveProblems/1ced8b3a9856f929f3d746c8bf7aa462 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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