rick
если не сложно, можно чуть подробнее про ее наследование, как это сделать и зачем?
Нашёл в инете форма и прикрепление формы от Sunderland93
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(420, 301)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
MainWindow.setMinimumSize(QtCore.QSize(420, 301))
MainWindow.setMaximumSize(QtCore.QSize(420, 301))
icon = QtGui.QIcon.fromTheme("drive-removable-media")
MainWindow.setWindowIcon(icon)
self.centralWidget = QtWidgets.QWidget(MainWindow)
self.centralWidget.setObjectName("centralWidget")
self.label = QtWidgets.QLabel(self.centralWidget)
self.label.setGeometry(QtCore.QRect(10, 0, 59, 21))
self.label.setObjectName("label")
self.comboBox = QtWidgets.QComboBox(self.centralWidget)
self.comboBox.setGeometry(QtCore.QRect(10, 20, 401, 32))
self.comboBox.setObjectName("comboBox")
self.label_2 = QtWidgets.QLabel(self.centralWidget)
self.label_2.setGeometry(QtCore.QRect(10, 60, 59, 18))
self.label_2.setObjectName("label_2")
self.toolButton = QtWidgets.QToolButton(self.centralWidget)
self.toolButton.setGeometry(QtCore.QRect(380, 80, 33, 34))
self.toolButton.setText("")
icon = QtGui.QIcon.fromTheme("document-open")
self.toolButton.setIcon(icon)
self.toolButton.setObjectName("toolButton")
self.label_3 = QtWidgets.QLabel(self.centralWidget)
self.label_3.setGeometry(QtCore.QRect(10, 120, 41, 18))
self.label_3.setObjectName("label_3")
self.lineEdit = QtWidgets.QLineEdit(self.centralWidget)
self.lineEdit.setGeometry(QtCore.QRect(10, 140, 201, 32))
self.lineEdit.setObjectName("lineEdit")
self.label_4 = QtWidgets.QLabel(self.centralWidget)
self.label_4.setGeometry(QtCore.QRect(220, 120, 71, 18))
self.label_4.setObjectName("label_4")
self.comboBox_3 = QtWidgets.QComboBox(self.centralWidget)
self.comboBox_3.setGeometry(QtCore.QRect(220, 140, 191, 32))
self.comboBox_3.setObjectName("comboBox_3")
self.comboBox_3.addItem("")
self.comboBox_3.addItem("")
self.comboBox_3.addItem("")
self.line = QtWidgets.QFrame(self.centralWidget)
self.line.setGeometry(QtCore.QRect(10, 180, 401, 16))
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.progressBar = QtWidgets.QProgressBar(self.centralWidget)
self.progressBar.setGeometry(QtCore.QRect(10, 210, 401, 23))
self.progressBar.setProperty("value", 0)
self.progressBar.setObjectName("progressBar")
self.cancelButton = QtWidgets.QPushButton(self.centralWidget)
self.cancelButton.setGeometry(QtCore.QRect(320, 260, 88, 34))
icon = QtGui.QIcon.fromTheme("dialog-cancel")
self.cancelButton.setIcon(icon)
self.cancelButton.setObjectName("cancelButton")
self.writeButton = QtWidgets.QPushButton(self.centralWidget)
self.writeButton.setGeometry(QtCore.QRect(230, 260, 88, 34))
icon = QtGui.QIcon.fromTheme("dialog-ok")
self.writeButton.setIcon(icon)
self.writeButton.setObjectName("writeButton")
self.aboutButton = QtWidgets.QPushButton(self.centralWidget)
self.aboutButton.setGeometry(QtCore.QRect(10, 260, 88, 34))
icon = QtGui.QIcon.fromTheme("help-about")
self.aboutButton.setIcon(icon)
self.aboutButton.setObjectName("aboutButton")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralWidget)
self.lineEdit_2.setGeometry(QtCore.QRect(10, 80, 361, 32))
self.lineEdit_2.setObjectName("lineEdit_2")
MainWindow.setCentralWidget(self.centralWidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "QImageWriter"))
self.label.setText(_translate("MainWindow", "Device:"))
self.label_2.setText(_translate("MainWindow", "ISO:"))
self.label_3.setText(_translate("MainWindow", "Label:"))
self.lineEdit.setText(_translate("MainWindow", "USB_STICK"))
self.label_4.setText(_translate("MainWindow", "Filesystem:"))
self.comboBox_3.setItemText(0, _translate("MainWindow", "FAT32"))
self.comboBox_3.setItemText(1, _translate("MainWindow", "NTFS"))
self.comboBox_3.setItemText(2, _translate("MainWindow", "EXT4"))
self.cancelButton.setText(_translate("MainWindow", "Cancel"))
self.writeButton.setText(_translate("MainWindow", "Write"))
self.aboutButton.setText(_translate("MainWindow", "About"))
#!/usr/bin/env python3
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
from mainwindow import *
import sys
class MainProg (Ui_MainWindow):
def __init__(self, window):
Ui_MainWindow.__init__(self)
self.setupUi(window)
self.aboutButton.clicked.connect(self.about)
def about(self):
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setWindowTitle('About')
msg.exec_()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = QMainWindow()
prog = MainProg(window)
window.show()
sys.exit(app.exec_())
Когда ты наследуешься, всё содержимое формы наследуется и у класса появляются все атрибуты и методы формы. Если ты в дизайнере сделал кнопку, то после наследования ты можешь к ней обращаться, будто ты её создал в классе.
Вот у него self.aboutButton унаследована от формы и он прикрепляет сигнал от неё к слоту.