import sys
from PyQt5.QtWidgets import QMainWindow,QApplication,QDesktopWidget
from PyQt5.QtGui import QIcon #图标
class FirstMainWin(QMainWindow): #对QMainWindow进行继承
def __init__(self,parent=None): #方法初始化parent=None保证QMainWindow是主窗口,parent=None传入父类的初始化中,下一个程序中有体现
super(FirstMainWin,self).__init__(parent) #super有两种方法继承python2:super(子类(即本方法), self).__init__(parent),
# 继承父类全部方法并进行初始化,super(子类(即本方法), self).父类中的方法即只继承该方法(没有初始化的方法不可使用)
#python3:super().初始化或者方法(.后内容相同)
#设置主窗口的标题
self.setWindowTitle('主窗口')
#设置窗口的尺寸
self.resize(400,300)
#状态栏(右下角)
self.status=self.statusBar()
self.status.showMessage('只存在5秒的消息',5000)#单位是毫秒
def center(self):#窗口位置设置
#获取屏幕坐标系
screen=QDesktopWidget.screenGeometry()
#获取窗口坐标系
size=self.geometry()
newLeft=(screen.width()-size.width())/2
newTop=(screen.heigth()-size.heigth())/2
self.move(newLeft,newTop)
if __name__=='__main__': #这个设置是为了只能在这个下面才可以使用上面的脚本
app=QApplication(sys.argv)#常规操作
app.setWindowIcon(QIcon('./image/11.png'))#注意引用时,图片的目录应在代码的相同位置或者添加一个文件夹,点必不可少
main=FirstMainWin()#方法实例化
main.show() #图像显示
sys.exit(app.exec_())#进入循环,不然窗口会自动关闭