Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
class MainWindow(QWidget):
    def __init__(self):
        super(MainWindow, self).__init__()

        # Importing data from Qt UI file
        uic.loadUi("pathSelection.ui", self)

        self.nameBrowse1.clicked.connect(self.browseFiles1)
        self.nameBrowse2.clicked.connect(self.browseFiles2)

        if self.fileName1 == self.fileName2:
            print("Both files are same")
        else:
            print("Both files are different")

    def browseFiles1(self):
        fname1 = QtWidgets.QFileDialog.getExistingDirectory(
            None, 'Select folder:', './img', QtWidgets.QFileDialog.ShowDirsOnly   
        )
        if fname1:
            self.fileName1.setText(fname1)

    def browseFiles2(self):
        fname2 = QtWidgets.QFileDialog.getExistingDirectory(
            None, 'Select folder:', './img', QtWidgets.QFileDialog.ShowDirsOnly   
        )
        if fname2:
            self.fileName2.setText(fname2)


What I have tried:

In this code, I am trying to make the if-statement work. I am browsing two folders and I want that if a user selects two same folders location, then the message should appear in the terminal that both files are the same, and if not then the message should be the opposite.

But when I run the code, the else statement appears in the terminal. Although I didn't select any file. But if I browse files then it does not give me any message.
Posted
Comments
Richard MacCutchan 23-Jan-21 5:25am    
What are the actual values of the two filenames?
ibilalkayy 23-Jan-21 5:44am    
Actual values are the path of the filename that I browse
Richard MacCutchan 23-Jan-21 11:08am    
But what are the actual values when you run the code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900