I am trying to build a simple GUI using PyQT5, with 3 buttons to open file browsers and one more to run processing with the selected files, but I can\'t get my buttons to connec
The problem is that you are not keeping any persistent reference to the Ctrl()
instance you are creating. This results in python garbage collecting it as soon as the instance is created.
To solve the issue, just assign it to a variable:
def main():
"""Main function."""
# Create an instance of `QApplication`
app = QApplication(sys.argv)
# Show the app's GUI
view = UI()
view.show()
setup = {}
# Create instance of the controller
ctrl = Ctrl(setup=setup, view=view)
# Execute app's main loop
sys.exit(app.exec_())
Some considerations:
self
, but in that case it refers to the Ctrl
instance, while the argument should be the UI
instance instead (which will result in a crash, as Qt will get an unexpected argument type); you can use self._view
instead, but, as said, the whole separation in this case just makes things unnecessarily complex;from PyQt5.QtWidgets import (QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget, QFileDialog)