PyUIC 产生的Python文件如何运行出界面,以及其中自定义的槽函数如何实现具体代码。
Qtdesigner设计出界面,保存为UI文件,通过PyUIC转换为了Python文件mainUI.py,在另一个python文件main.py中导入了该文件的类(为了将UI单独分离出来,方便编辑UI),
from mainUI import Ui_MainWindow
- 之后该如何继续编写代码来使页面显示出来
- 再QtDesigner设计的时候自定义了槽函数openFile(),在main.py中如何实现该函数的细节
补上PyUIC转换出的python文件内容:
# -*- 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"))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1.添加app启动的主函数啊
2.打开文件细节一般就是使用者通过窗口选择路径,程序open路径文件,读取内容,显示到文本框(或其它用途)