PyQt5 QPushButton 触发不止一次
PyQt5 QPushButton fires more than once
在 Python3 PyQt5 中有没有办法获取信号连接到插槽的次数,即:
QPushButton.clicked.connect(foo)
想知道在发出信号时插槽 (foo) 将被调用多少次?
我不是在谈论代码中的计数器,而是从
中获取该数字的方法
PyQt5 存储该信息的位置
机械上我会考虑放置一个
print('any message') #like this you are directly notified via the console console or terminal,...
在您将要调用的每个方法中,例如:
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import QApplication, QPushButton
import sys
#import other modules
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
# Geometry of main window:
self.setGeometry(200, 200, 300, 400)
# create a Button Btn1
self.Btn1 = QPushButton('Fire Button :)', self)
self.Btn1.clicked.connect(self.Fire1)
self.Btn1.move(0, 0)
self.Btn2 = QPushButton('2nd Fire_Button :)', self)
self.Btn2.clicked.connect(self.Fire2)
self.Btn2.move(130, 0)
def Fire1(self):
print('Worked, Fired once!...details(...)')
def Fire2(self):
print('It is Working, but he needs to add his code! Thanks')
self.setStyleSheet('background:rgba(80, 97, 15, 184);')
self.resize(600, 210)
pass
app = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())
我的回答对你有帮助(很好!),否则请向我们提供更详细的信息或你正在处理的代码示例,以便更好地帮助你...
在 Python3 PyQt5 中有没有办法获取信号连接到插槽的次数,即:
QPushButton.clicked.connect(foo)
想知道在发出信号时插槽 (foo) 将被调用多少次?
我不是在谈论代码中的计数器,而是从
中获取该数字的方法PyQt5 存储该信息的位置
机械上我会考虑放置一个
print('any message') #like this you are directly notified via the console console or terminal,...
在您将要调用的每个方法中,例如:
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import QApplication, QPushButton
import sys
#import other modules
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
# Geometry of main window:
self.setGeometry(200, 200, 300, 400)
# create a Button Btn1
self.Btn1 = QPushButton('Fire Button :)', self)
self.Btn1.clicked.connect(self.Fire1)
self.Btn1.move(0, 0)
self.Btn2 = QPushButton('2nd Fire_Button :)', self)
self.Btn2.clicked.connect(self.Fire2)
self.Btn2.move(130, 0)
def Fire1(self):
print('Worked, Fired once!...details(...)')
def Fire2(self):
print('It is Working, but he needs to add his code! Thanks')
self.setStyleSheet('background:rgba(80, 97, 15, 184);')
self.resize(600, 210)
pass
app = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())
我的回答对你有帮助(很好!),否则请向我们提供更详细的信息或你正在处理的代码示例,以便更好地帮助你...