PyQt5 GUI signal called multiple times [duplicate]
The reason why the output is being printed three times, is because of the way you named the signal handlers. The connect slots by name feature will automatically connect signal handlers that are named using the following format:
on_[object name]_[signal name]
Since the clicked
signal has two overloads, and you added an explicit connection yourself, that makes three connections in total.
The easiest way to fix this, is to change the names of your handlers to something like this:
self.ui.cancel.clicked.connect(self.handleCloseClicked)
self.ui.choose.clicked.connect(self.handleChooseClicked)
def handleCloseClicked(self):
...
def handleChooseClicked(self):
...
The other issue is caused by incorrect handling of the if/elif
block. It should probably look more like this:
...
elif self.ui.size_4gb.isChecked():
var.persistence_size = "4gb"
else:
print "Please choose persistence size..."
QtGui.QMessageBox.information(self, 'No size...', 'No persistence size selected.\n\nPlease choose persistence size and click Choose.')
return
print "Selected", var.persistence_size
QtGui.qApp.closeAllWindows()