有没有办法在点击命令后禁用它。
我试图使用下面的代码来实现它。
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_()
显然会发生什么,当我再次单击该按钮时,它会再次遍历该值并稍后更改该值。
但是当我用这种方法制作它时它成功了。
m = 1
def do_it():
global m
m =0
while m == 1:
do_it()
print("m is equal to 1")