Is there a way to disable the command after clicking on it.
I have tried to make it using the code below.
from PyQt5.QtWidgets import *
import sys
class window(QWidget):
def __init__(self):
super().__init__()
self.btn = QPushButton("click me")
self.btn.clicked.connect(self.stopcommand_after_clicking)
vbox = QVBoxLayout()
vbox.addWidget(self.btn)
self.setLayout(vbox)
def stopcommand_after_clicking(self):
m = 1
def clicked():
global m#but after the command happens the value of m changes
# and so the command must not happen again
m = 2
print("clicked")
pass
if m == 1:#because m is equal to one the command is gonna happen
clicked()
app = QApplication(sys.argv)
windo = window()
windo.show()
app.exec_()
apparently what happens that when I click the button again it goes through the value again and it changes the value later.
But it succeed when I make it with this method.
m = 1
def do_it():
global m
m =0
while m == 1:
do_it()
print("m is equal to 1")