- 指定界面大小
- 获取屏幕大小
- 根据界面宽高计算位置
- 设置左上角坐标,及界面宽高
import sys
from PyQt5.QtWidgets import QMainWindow, QDesktopWidget, QApplication
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.width = 800
self.height = 600
screen = QDesktopWidget().screenGeometry()
self.top = int((screen.width() - self.width) / 2)
self.left = int((screen.height() - self.height) / 2)
self.setGeometry(self.top, self.left, self.width, self.height)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())