U
U
UNy2018-02-22 23:53:57
Python
UNy, 2018-02-22 23:53:57

Aggregation in python?

Can you give a simple example of aggregation in python? How often do you use aggregation when creating web applications? When should you use it and not inheritance?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-02-24
@UNy

Here is an example of aggregation in python in this case i can't use inheritance

import os
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtCore import Qt


class EnterName(QWidget):
    text_value = pyqtSignal(str)
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 300, 50)
        self.setWindowTitle('Введите имя')
        

        self.button = QPushButton('Сохранить', self)
        self.button.clicked.connect(self.bEvent)
        self.button.move(120, 30)

        self.lEdid = QLineEdit(self)
        self.lEdid.setGeometry(0, 0, 300, 30)
        

    @pyqtSlot()
    def bEvent(self):
        self.text_value.emit(self.lEdid.text())
        self.hide()


class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 420, 280)
        self.setWindowTitle('Exsample')
        self.setWindowModality(Qt.WindowModal)

        self.button = QPushButton('Имя', self)
        self.button.move(180, 260)
        self.button.clicked.connect(self.bEvent)

        self.tb = QTextBrowser(self)
        self.tb.setGeometry(0, 0, 420, 260)

        self.eName = EnterName()
        self.eName.text_value.connect(self.signalHandler)

    def bEvent(self):
        self.eName.show()

    def signalHandler(self, text):
        self.tb.append(text)

if __name__ == '__main__':

    app = QApplication(sys.argv)
    example = Example()
    example.show()
    sys.exit(app.exec_())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question