I would like to know why when I do btn.clicked.connect(self.close_application())
the program closed instantly. It seems like self.close_application
executed even though I did not click the print button. However, it works as intended when I use btn.clicked.connect(self.close_application)
.
Can anyone explain to me why using self.close_applciation()
results in my Q window to be instantly closed without even me clicking the "print" button?
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(50,50,500,500)
self.setWindowTitle("Kenny")
self.home()
self.show()
def home(self):
self.FullName()
self.show()
def FullName(self):
win = QWidget(self)
flo=QFormLayout()
btn = QtGui.QPushButton("&Print",self)
btn.clicked.connect(self.close_application)
flo.addRow(btn ,QPushButton("Cancel"))
self.setCentralWidget(win)
win.setLayout(flo)
win.show()
def close_application(self):
print("Bye Bye")
sys.exit()
def run():
app = QtGui.QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())
run()