I have two classes for making pyqt5 windows. Inside class one I have a button with a function it is connected to.
Class One:
from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5.QtWidgets import QApplication, QMainWindow
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.btn = QtWidgets.QPushButton(self)
self.btn.setText('Button')
self.btn.clicked.connect(self.func)
def func(self):
# ...
In class two, I have the same button and need the function, but I don't want to copy and paste code.
Class Two:
class OtherWindow(QtWidgets.QDialog):
def __init__(self):
super(OtherWindow, self).__init__()
self.btn = QtWidgets.QPushButton(self)
self.btn.setText('Button')
# want the function but don't want to copy/paste
Would it be considered "bad practice" to do this? If so, what can I do instead?