Python Qt 入门教程

1、官网下载PySide2、pyqt5-tools安装qt环境

pip install PySide2

pip install pyqt5-tools

2、安装后桌面

   

Python Qt 入门教程_第1张图片

3、在designer中画好ui页面后,通过python代码加载

from collections import OrderedDict
from PySide2 import QtWidgets
from PySide2.QtCore import QFile
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QFileDialog


class MailSend:

    def __init__(self):
        # 加载布局
        self.item = None
        q_file = QFile("ui/send-mail.ui")
        q_file.open(QFile.ReadOnly)
        q_file.close()
        self.window = QUiLoader().load(q_file)
        # 绑定导入事件
        self.window.excel_btn.clicked.connect(self.import_excel)

    def import_excel(self):
        print("导入excel")
        file_dialog = QFileDialog()
        files, file_type = file_dialog.getOpenFileNames(None, "./", '文件(*.xlsx)')
        self.data_from_excel()

    def data_from_excel(self):
        dict_ = OrderedDict({'1号': '张三,[email protected]', '2号': '李四,[email protected]', '3号': '王五, [email protected]'})
        for key, value in dict_.items():
            self.item = QtWidgets.QListWidgetItem(self.window.mail_send_list)
            self.item.setText(key+": "+value)
            self.item.setToolTip(value)

  创建布局对象

from PySide2.QtWidgets import QApplication
from mail_send import MailSend


def main():
    app = QApplication([])
    mail_send = MailSend()
    mail_send.window.show()

    # app.setWindowIcon()
    app.exec_()


if __name__ == "__main__":
    main()

   4、PyInstaller程序包发布

pyinstaller  main.py   --noconsole --hidden-import  PySide2.QtXml
COPY  ./ui   ./dist/main

你可能感兴趣的:(c/c++,qt,ui,开发语言)