1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import sys from PyQt5.QtWidgets import QApplication,QWidget,QDesktopWidget class Window(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 300, 200) self.setWindowTitle('窗口居中') 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) window = Window() sys.exit(app.exec_()) |
- 本文固定链接: http://www.u3d8.com/?p=1357
- 转载请注明: 网虫虫 在 u3d8.com 发表过