pythonbuttonpyqt5editline

Why the editText doesn't show the user input in Python class?


I have a Python class that display a window that includes 2 text filed and 2 buttons.

Where the user enter a string in the first edit text and on click on the (open button) the second edit text will display the user input.

The problem is that on the click on the button there is nothing displayed in the text filed.

Code:

'''
1- import the libraries from the converted file
2- import the converted file 
'''
from PyQt5 import QtCore, QtGui, QtWidgets
import pathmsgbox 
import os 
import pathlib

class path_window(pathmsgbox.Ui_PathMSGbox):


    def __init__(self,windowObject ):
        self.windowObject = windowObject
        self.setupUi(windowObject)
        self.windowObject.show()
        self.getText()


    '''
    get the userInput  from the EditLine
    '''   

    def getText(self):
        inputUser = self.pathEditLine.text()
        outPutUser = self.outputPathName.setText(inputUser)
        print(outPutUser)

    def puchBtn(self):
        openButton = self.PathOpenBtn.clicked.connect(self.getText)    
'''
function that exit from the system after clicking "cancel"
'''
def exit():
    sys.exit()

'''
define the methods to run only if this is the main module deing run
the name take __main__ string only if its the main running script and not imported 
nor being a child process
'''
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    PathMSGbox = QtWidgets.QWidget()
    pathUi = path_window(PathMSGbox)
    pathUi.pathCancelBtn.clicked.connect(exit)
    sys.exit(app.exec_())

Solution

  • You're not connecting your clicked button event to the function - the binding is in a function that is never called.

    Simply connect your button in the class initialization:

    class path_window(pathmsgbox.Ui_PathMSGbox):
    
    
        def __init__(self,windowObject ):
            self.windowObject = windowObject
            self.setupUi(windowObject)
            self.windowObject.show()
            self.PathOpenBtn.clicked.connect(self.getText)
            self.getText()