[Pyqt5 accessing violation of variable storing folder_path taken from getExistingDirectory function into another function]
created a simple GUi using pyqt5 where I am taking the input directory path using the get existing directory function and I am storing it in a variable but I am unable to access the variable or the folder path in another function. In the Gui I take two paths one is input folder path and the other is output folder path and I created a 3rd button which when clicked will go into a function and then i am trying to use the both paths taken and send them as input arguments to another py file and run it using subprocess but I am unable to get the folder paths in my third function and I want to pass both paths as input arguments. What will be the best way to do it. here is the code
class App(QWidget): def init (self): super(). init () self.setWindowTitle(‘Avizo’) self.setWindowIcon(QtGui.QIcon(‘logo.png’)) self.resize(600,239)
self.button1 = QPushButton('Input folder')
self.button1.setGeometry(QtCore.QRect(30, 30, 681, 28))
self.button1.clicked.connect(self.get_input_dir)
self.button2 = QPushButton('Select Outputfolder')
self.button2.setGeometry(QtCore.QRect(30, 80, 681, 28))
self.button2.clicked.connect(self.get_Output_dir)
self.button4 = QPushButton('calculate')
self.button4.setGeometry(QtCore.QRect(30, 180, 161, 28))
self.button4.clicked.connect(self.calculate)
layout = QVBoxLayout()
layout.addWidget(self.button1)
layout.addWidget(self.button2)
layout.addWidget(self.button3)
self.setLayout(layout)
self.initUI()
def initUI(self):
self.show()
def get_input_dir(self):
input_path = QtWidgets.QFileDialog.getExistingDirectory(self, 'Select Output Folder')
print(input_path)
#print(image_paths)
return input_path
def get_Output_dir(self):
output_path = QtWidgets.QFileDialog.getExistingDirectory(self, 'Select Output Folder')
#print(output_path)
def cropmodule(self):
x=get_input_dir()
print(x)
subprocess.Popen(['python', 'file.py'])
if name == 'main': app = QApplication(sys.argv)
Demo = App()
app.exec_()