0
点赞
收藏
分享

微信扫一扫

SAdb项目第三章-Pyside6资源文件与UI文件的使用

艾米吖 2024-06-24 阅读 25
pythonpyqtqt

使用UI转换的Py文件后运行程序

from UI.index import Ui_Form
from PySide6.QtWidgets import QWidget, QApplication


class Index_UI(QWidget, Ui_Form):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.show()


if __name__ == '__main__':
    app = QApplication([])
    index = Index_UI()
    app.exec()

直接使用UI文件

from PySide6.QtCore import QFile
from PySide6.QtUiTools import QUiLoader
from PySide6.QtWidgets import QWidget, QApplication


class Index_UI:

    def load_ui(self, file_name):
        loader = QUiLoader()
        file = QFile(file_name)
        file.open(QFile.ReadOnly)
        ui = loader.load(file)
        file.close()
        return ui


if __name__ == '__main__':
    app = QApplication([])
    index = Index_UI().load_ui(r'UI\index.ui')
    index.show()
    app.exec()
from PySide6.QtCore import QFile
from PySide6.QtUiTools import QUiLoader
from PySide6.QtWidgets import QWidget, QApplication
import resources_rc

class Index_UI:
    def __init__(self):
        self.ui = None

    def load_ui(self, file_name):
        loader = QUiLoader()
        file = QFile(file_name)
        file.open(QFile.ReadOnly)
        self.ui = loader.load(file)
        file.close()
        self.ui.show()


if __name__ == '__main__':
    app = QApplication([])
    index = Index_UI()
    index.load_ui(r'UI\index.ui')
    app.exec()

展示结果

下一章讲述designer的具体使用,以及工具UI的具体布局

举报

相关推荐

0 条评论