0
点赞
收藏
分享

微信扫一扫

让窗口居中

扒皮狼 2022-02-12 阅读 41
python
import sys
from PyQt5.QtWidgets import QDesktopWidget,QMainWindow, QApplication
from PyQt5.QtGui import QIcon

class CenterForm(QMainWindow):
    def __init__(self, parent=None):
        super(CenterForm, self).__init__(parent)

        # 设置主窗口的标题
        self.setWindowTitle("让窗口居中")

        # 设置窗口的尺寸
        self.resize(400, 300)
        self.center()
        self.status = self.statusBar()
        self.status.showMessage('只存在5s的消息', 5000)

    def center(self):
        # 获取屏幕坐标系
        screen = QDesktopWidget().screenGeometry()
        # 获取窗口坐标系
        size = self.geometry()

        newLeft = (screen.width()-size.width())/2
        newTop = (screen.height() -size.height())/2

        self.move(newLeft, newTop)

if __name__ == '__main__':
    app = QApplication(sys.argv)

    app.setWindowIcon(QIcon("./MainWindow/dragon.ico"))
    main = CenterForm()
    main.show()

    sys.exit(app.exec_())




















举报

相关推荐

0 条评论