0

Как сделать так чтобы элемент не заменялся, а как бы заполнял массив.

#!/usr/bin/python3
# -*- coding: utf-8 -*-


from PyQt5 import QtGui
from PyQt5.QtWidgets import (QApplication, QWidget, QDesktopWidget, 
    QGridLayout, QVBoxLayout, QPushButton, QInputDialog, QLabel, QHBoxLayout,
    QToolTip, QMessageBox, QLineEdit, QTextEdit,QFrame, QLCDNumber, QSlider)
from PyQt5.QtGui import QIcon, QFont, QColor


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

        self.initUI()

    def initUI(self):
        self.resize(800, 440)
        self.center()
        self.setWindowTitle('merge sort')
        self.setWindowIcon(QIcon('web.png'))    

        self.btn = QPushButton('Enter array', self)
        self.btn.clicked.connect(self.gettext)

        layout = QHBoxLayout(self)
        layout.addWidget(self.btn)

        # Array input field
        self.lbl = QLabel('<b>Enter array:</b>', self)
        layout.addWidget(self.lbl)
        # output element
        self.le = QLabel(self)
        layout.addWidget(self.le)

    #  Asked whether you really sure you want to close
    def closeEvent(self, event):
        reply = QMessageBox.question(self, 'Message',
            "Are you sure to quit?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)

        if reply == QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()   

    # Makes the window was centered
    def center(self):
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter( cp )
        self.move(qr.topLeft()) 

    # Enter array
    def gettext(self):
        num, ok = QInputDialog.getInt(self, 'integer input dualog',
            'Enter element:')      
        if ok:
            self.le.setText(str(num))


if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)

    ex = Example()
    ex.show()

    sys.exit(app.exec_())
1
  • 1. Слишком много ненужного кода. 2. Не нашел в коде или в вопросе озвученный массив
    – gil9red
    16 мая 2017 в 19:36

1 ответ 1

2

Вот добавление через метод списков append:

# инициализация массива
self.arr = []

# добавления в массив
# Enter array
def getnum(self):
    num, ok = QInputDialog.getInt(self, 'integer input dualog', 'Enter element:')      
    if ok:
        self.arr.append(num)
        self.output.setText(str(self.arr))
0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.