-1

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_())
K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
Pyt Leb
  • 99
  • 2
  • 10

1 Answers1

0

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()
Gsk
  • 2,929
  • 5
  • 22
  • 29
  • i tried your answer it works but still the print (outPutUser) display None in the console – Pyt Leb Mar 17 '18 at 16:14
  • when you call `print(outPutUser)` you are actually printing the `.setText` return, which is correctly `None`. If you want to print the input of the user, call `print(inputUser)` – Gsk Mar 17 '18 at 16:20
  • i have another question how to make the user enter a path for a directory where the open Button will open the entered path after it check it if exist – Pyt Leb Mar 17 '18 at 16:28
  • you may want to use `os.path.exist(path)` to verify if a path exist, and `os.listdir(path)` to get a list of the files inside that directory, but it's a pretty long answer. Resolve this question and open a more specific answer on this – Gsk Mar 17 '18 at 16:32