Есть автокликер с двумя кнопка Start и Stop.
При нажатий Start кликер работает, но окно приложения не отвечает.
Остановить программу можно выключив.
Как исправить эту проблему?
from PyQt5 import QtCore, QtGui, QtWidgets
import time
import pyautogui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setFixedSize(250, 250)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.name = QtWidgets.QLabel(self.centralwidget)
self.name.setGeometry(QtCore.QRect(15, 15, 70, 50))
font = QtGui.QFont()
font.setFamily("Attractive Heavy")
font.setPointSize(18)
font.setBold(True)
font.setWeight(75)
self.name.setFont(font)
self.name.setStyleSheet("color: rgb(255, 255, 255);")
self.name.setObjectName("name")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(15, 50, 61, 20))
font = QtGui.QFont()
font.setFamily("Attractive Heavy")
font.setPointSize(8)
self.label_2.setFont(font)
self.label_2.setStyleSheet("color: rgb(255, 255, 255);")
self.label_2.setObjectName("label_2")
self.start = QtWidgets.QPushButton(self.centralwidget)
self.start.setGeometry(QtCore.QRect(60, 115, 130, 30))
font = QtGui.QFont()
font.setFamily("Attractive Heavy")
font.setPointSize(11)
font.setBold(False)
font.setItalic(False)
font.setUnderline(False)
font.setWeight(50)
font.setStrikeOut(False)
font.setKerning(True)
self.start.setFont(font)
self.start.setStyleSheet("QPushButton#start {\n"
" background-color: rgb(255, 255, 255);\n"
" border-radius: 12%;\n"
"}\n"
"\n"
"QPushButton#start:hover {\n"
" border: 1.5px solid #000000;\n"
"}\n"
"\n"
"QPushButton#start:pressed {\n"
" background-color: rgb(0, 0, 0);\n"
" color: #ffffff;\n"
" border-color: #ffffff;\n"
"}")
self.start.setObjectName("start")
self.background = QtWidgets.QLabel(self.centralwidget)
self.background.setEnabled(True)
self.background.setGeometry(QtCore.QRect(0, 0, 250, 250))
self.background.setText("")
self.background.setTextFormat(QtCore.Qt.AutoText)
self.background.setPixmap(QtGui.QPixmap("../../../memes/images.jpg"))
self.background.setScaledContents(True)
self.background.setObjectName("background")
self.stop = QtWidgets.QPushButton(self.centralwidget)
self.stop.setGeometry(QtCore.QRect(60, 169, 130, 30))
font = QtGui.QFont()
font.setFamily("Attractive Heavy")
font.setPointSize(11)
font.setBold(False)
font.setWeight(50)
self.stop.setFont(font)
self.stop.setStyleSheet("QPushButton#stop {\n"
" background-color: rgb(255, 255, 255);\n"
" border-radius: 12%;\n"
"}\n"
"\n"
"QPushButton#stop:hover {\n"
" border: 1.5px solid #000000;\n"
"}\n"
"\n"
"QPushButton#stop:pressed {\n"
" background-color: rgb(0, 0, 0);\n"
" color: #ffffff;\n"
" border-color: #ffffff;\n"
"}")
self.stop.setObjectName("stop")
self.background.raise_()
self.name.raise_()
self.label_2.raise_()
self.start.raise_()
self.stop.raise_()
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.add_functions()
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Click!"))
self.name.setText(_translate("MainWindow", "Click!"))
self.label_2.setText(_translate("MainWindow", "by SpArr0w"))
self.start.setText(_translate("MainWindow", "Start"))
self.stop.setText(_translate("MainWindow", "Stop"))
def add_functions(self):
self.start.clicked.connect(self.mouseclick)
self.stop.clicked.connect(self.powerfalse)
def mouseclick(self):
power = True
while True:
time.time()
pyautogui.click()
while True:
time.sleep(0.1)
pyautogui.doubleClick()
time.time()
def powerfalse(self):
power = False
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())