When I click a button inf its work and it is going to an infinite loop and I want to click another button to stop the Program but the problem I can not click another button (stop button) because my GUI is freezing this my code
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
def retranslateUi( MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
infButton.setText(_translate("MainWindow", "inf"))
stopButton.setText(_translate("MainWindow", "stop"))
def inf_lp():
while True:
print (1)
def stop_lp():
exit(0)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
centralwidget = QtWidgets.QWidget(MainWindow)
centralwidget.setObjectName("centralwidget")
infButton = QtWidgets.QPushButton(centralwidget)
infButton.setGeometry(QtCore.QRect(160, 110, 89, 25))
infButton.setObjectName("infButton")
infButton.clicked.connect(inf_lp)
stopButton = QtWidgets.QPushButton(centralwidget)
stopButton.setGeometry(QtCore.QRect(400, 100, 89, 25))
stopButton.setObjectName("stopButton")
stopButton.clicked.connect(stop_lp)
MainWindow.setCentralWidget(centralwidget)
menubar = QtWidgets.QMenuBar(MainWindow)
menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))
menubar.setObjectName("menubar")
MainWindow.setMenuBar(menubar)
statusbar = QtWidgets.QStatusBar(MainWindow)
statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(statusbar)
retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
This image for my GUI
I try to follow this. but I can not understand how to solve this problem because I do not use class in my code