T
T
TchernyavskyDaniil2018-05-03 19:15:41
Python
TchernyavskyDaniil, 2018-05-03 19:15:41

How to connect two fields and button pyqt5?

Good evening. Stupid question. There are 2 fields lineEdit 1/2, there is a button pushButton
I do not quite understand how to make it so that when pushButton is pressed, for example, output the contents of lineEdit 1 and 2 to another function as parameters.
Tell me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-05-04
@TchernyavskyDaniil

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


class Example(QMainWindow):
    send = pyqtSignal(tuple)
    def __init__(self):
        super().__init__()
        self.initUI()
        
    @pyqtSlot()
    def initUI(self):
        self.setWindowTitle("Пример")
        self.setGeometry(300, 300, 250, 100)

        self.line_edit = QLineEdit(self)
        self.line_edit.setGeometry(0, 0, 250, 33)
        
        self.line_edit_2 = QLineEdit(self)
        self.line_edit_2.setGeometry(0, 33, 250, 33)

        self.button = QPushButton('Запуск', self)
        self.button.clicked.connect(self.start)
        self.button.setGeometry(0, 66, 250, 34)
        
        self.send.connect(self.print)

    def start(self):
        # print("LineEdit get text:", self.line_edit.text())
        # print("LineEdit2 get text:", self.line_edit_2.text())

        str_tuple = (self.line_edit.text(), self.line_edit_2.text())
        self.send.emit(str_tuple)
        
    def print(self, data):
        print(data)
        
if __name__ == '__main__':
    application = QApplication(sys.argv)
    window = Example()
    window.show()
    sys.exit(application.exec_())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question