鍍金池/ 問答/Python  網(wǎng)絡(luò)安全/ PyUIC 產(chǎn)生的Python文件如何運(yùn)行出界面,以及其中自定義的槽函數(shù)如何實(shí)現(xiàn)

PyUIC 產(chǎn)生的Python文件如何運(yùn)行出界面,以及其中自定義的槽函數(shù)如何實(shí)現(xiàn)具體代碼。

Qtdesigner設(shè)計(jì)出界面,保存為UI文件,通過PyUIC轉(zhuǎn)換為了Python文件mainUI.py,在另一個(gè)python文件main.py中導(dǎo)入了該文件的類(為了將UI單獨(dú)分離出來,方便編輯UI),

from mainUI import Ui_MainWindow
  1. 之后該如何繼續(xù)編寫代碼來使頁面顯示出來
  2. 再Q(mào)tDesigner設(shè)計(jì)的時(shí)候自定義了槽函數(shù)openFile(),在main.py中如何實(shí)現(xiàn)該函數(shù)的細(xì)節(jié)

補(bǔ)上PyUIC轉(zhuǎn)換出的python文件內(nèi)容:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'mainUI.ui'
#
# Created by: PyQt5 UI code generator 5.10
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.gridLayoutWidget.setGeometry(QtCore.QRect(230, 160, 160, 181))
        self.gridLayoutWidget.setObjectName("gridLayoutWidget")
        self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setObjectName("gridLayout")
        self.toolButton_4 = QtWidgets.QToolButton(self.gridLayoutWidget)
        self.toolButton_4.setObjectName("toolButton_4")
        self.gridLayout.addWidget(self.toolButton_4, 2, 0, 1, 1)
        self.toolButton_3 = QtWidgets.QToolButton(self.gridLayoutWidget)
        self.toolButton_3.setObjectName("toolButton_3")
        self.gridLayout.addWidget(self.toolButton_3, 1, 0, 1, 1)
        self.toolButton = QtWidgets.QToolButton(self.gridLayoutWidget)
        self.toolButton.setObjectName("toolButton")
        self.gridLayout.addWidget(self.toolButton, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 30))
        self.menubar.setObjectName("menubar")
        self.menuFile = QtWidgets.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionNew = QtWidgets.QAction(MainWindow)
        self.actionNew.setObjectName("actionNew")
        self.actionOpen = QtWidgets.QAction(MainWindow)
        self.actionOpen.setObjectName("actionOpen")
        self.actionSave = QtWidgets.QAction(MainWindow)
        self.actionSave.setObjectName("actionSave")
        self.actionClose = QtWidgets.QAction(MainWindow)
        self.actionClose.setObjectName("actionClose")
        self.actionQuite = QtWidgets.QAction(MainWindow)
        self.actionQuite.setObjectName("actionQuite")
        self.menuFile.addAction(self.actionNew)
        self.menuFile.addAction(self.actionOpen)
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.actionSave)
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.actionClose)
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.actionQuite)
        self.menubar.addAction(self.menuFile.menuAction())

        self.retranslateUi(MainWindow)
        self.toolButton_4.clicked.connect(MainWindow.close)
        self.toolButton_3.clicked.connect(MainWindow.openFile)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.toolButton_4.setText(_translate("MainWindow", "Quit"))
        self.toolButton_3.setText(_translate("MainWindow", "Open"))
        self.toolButton.setText(_translate("MainWindow", "New"))
        self.menuFile.setTitle(_translate("MainWindow", "Fi&le"))
        self.actionNew.setText(_translate("MainWindow", "New"))
        self.actionOpen.setText(_translate("MainWindow", "Open"))
        self.actionSave.setText(_translate("MainWindow", "Save"))
        self.actionClose.setText(_translate("MainWindow", "Close"))
        self.actionQuite.setText(_translate("MainWindow", "Quit"))

回答
編輯回答
詆毀你

1.添加app啟動(dòng)的主函數(shù)啊
2.打開文件細(xì)節(jié)一般就是使用者通過窗口選擇路徑,程序open路徑文件,讀取內(nèi)容,顯示到文本框(或其它用途)

2018年7月17日 01:14