0

I am trying to make web scraper based on the term I put into the textbox using PyQT5. But, when I tried printing input term as test, it returns an empty string.I also tried QTextEdit.toPlainText(), but it still doesn't work.

It doesn't make sense to me that .text() method cannot return the text in the textbox.

What does make this problem?

import sys
from PyQt5.QtWidgets import (QPushButton, QApplication, QWidget, QGridLayout, QLabel, QLineEdit, QTextEdit)
from PyQt5.QtCore import pyqtSlot
class Scraper(QWidget):
    def __init__(self):
        super().__init__()

        self.initUI()
    

    def initUI(self):

        grid = QGridLayout()
        self.setLayout(grid)

        #Search button
        btn1 = QPushButton('&Search', self)

        #Assign input text
        TERM_input = QLineEdit(self)
        
        grid.addWidget(QLabel('Search Term:'), 0, 0)
        grid.addWidget(TERM_input, 0, 1)

        term = TERM_input.text()

        btn1.clicked.connect(lambda : print(term))

        self.setWindowTitle('Scraper')
        self.setGeometry(300, 300, 300, 200)
        self.show()

if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = Scraper()
    sys.exit(app.exec_())

Ilkyun Im
  • 129
  • 5

0 Answers0