PyQt(一)

来源:互联网 发布:淘宝账号解封成功案例 编辑:程序博客网 时间:2024/06/17 15:10

PyQt(一)

环境: pycharm、python3.6

插件安装
这里写图片描述
QtDesigner-界面设计
QtDesigner
PyUIC-ui转py
这里写图片描述
Pyqcc-资源转py
这里写图片描述

简单例子

import sysfrom PyQt5.QtWidgets import QMainWindow, QApplication, QAction, qApp, QWidget, QDesktopWidgetfrom PyQt5.QtGui import QIconfrom ui.ui_main import Ui_MainWindowclass Example(QMainWindow, Ui_MainWindow):    def __init__(self):        super().__init__()        self.setupUi(self)        self.initUI()    def initUI(self):        self.statusBar().showMessage("Ready")        exitAction = QAction(QIcon("Res/img/icon1.png"), "Exit1", self)        exitAction.setShortcut("Ctrl+Q")        exitAction.setStatusTip("exit application")        exitAction.triggered.connect(qApp.quit)        self.statusBar()        menubar = self.menuBar()        fileMenu = menubar.addMenu("&File")        fileMenu.addAction(exitAction)        self.toolBar = self.addToolBar("Exit")        self.toolBar.addAction(exitAction)        self.Center()    def Center(self):        # 居中        qr = self.frameGeometry()        cp = QDesktopWidget().availableGeometry().center()        qr.moveCenter(cp)        self.move(qr.topLeft())if __name__ == "__main__":    app = QApplication(sys.argv)    ex = Example()    ex.show()    sys.exit(app.exec_())

效果

这里写图片描述

图片资源的拆入

创建资源文件

这里写图片描述
这里写图片描述

创建前缀并添加文件

这里写图片描述
使用Pyqcc转换qrc文件得到py文件
这里写图片描述

原创粉丝点击