加载中...

PyQt5学习之第一个窗口

PyQt5学习之第一个窗口


用到的方法代码中都有标注,直接上代码

代码:

import sys
from PyQt5.QtWidgets import QMainWindow,QApplication,QDesktopWidget
from PyQt5.QtGui import QIcon   #添加图标

class FirstMainWin(QMainWindow):
    #初始化
    def __init__(self,parent=None):
        super(FirstMainWin,self).__init__(parent)

        #设置主窗口标题
        self.setWindowTitle('我的主窗口')

        #设置窗口尺寸
        self.resize(800,500)

        #状态栏
        self.status=self.statusBar()
        self.status.showMessage('该消息只会存在4秒',4000)

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

        #计算新的窗口坐标(窗口左上角坐标)
        newLeft=(screen.width()-size.width())/2
        newTop=(screen.top()-size.top())/2

        #移动窗口
        self.move(newLeft,newTop)

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

    #设置应用图标
    app.setWindowIcon(QIcon('./images/wxl.jpg'))
    main=FirstMainWin()
    main.show()
    #运行主循环
    sys.exit(app.exec_())

运行结果

image

posted @ 2022-02-01 18:44  我没有bug  阅读(42)  评论(0编辑  收藏  举报