admin管理员组

文章数量:1570215

# -*- coding: utf-8 -*-
'''
	PyQT5将窗口放在屏幕中间 
'''
from PyQt5.QtWidgets import QDesktopWidget, QApplication ,QMainWindow
import sys  
    
class Winform( QMainWindow): 
    
    def __init__(self, parent=None):
        super( Winform, self).__init__(parent)
          
        self.setWindowTitle('主窗口放在屏幕中间例子')  
        self.resize(370,  250)  
        self.center()  
          
    def center(self):  
    	# 获取屏幕的尺寸信息
        screen = QDesktopWidget().screenGeometry() 
        # 获取窗口的尺寸信息
        size = self.geometry()  
        # 将窗口移动到指定位置      
        self.move((screen.width() - size.width()) / 2,  (screen.height() - size.height()) / 2)  
  
if __name__ == "__main__": 
    app = QApplication(sys.argv)   
    win = Winform()  
    win.show()  
    sys.exit(app.exec_())  

效果如下:

本文标签: 放在显示屏幕窗口位置