我在表单上有三个按钮,例如,当我点击5%按钮时,它会打印5%。但由于某些原因,所有按钮的打印率为60%。
我真的不明白为什么?
我的代码如下。
class ThirdWindow(QWidget, Ui_Form3):
def __init__(self):
super(ThirdWindow, self).__init__()
self.dbu = DatabaseHandling.DatabaseUtility()
self.msl = None
# Show UI on screen + resize window
self.setupUi(self)
self.picIndicator.setPixmap(QPixmap("M:\QtProjects\\Resources\\138691.png"))
self.setFixedSize(350, 480)
# Define what should happen on button click
self.btnQuit.clicked.connect(lambda: self.close())
self.btnSixtyPercent.clicked.connect(lambda: self.check_clicked())
self.btnTenPercent.clicked.connect(lambda: self.check_clicked())
self.btnFivePercent.clicked.connect(lambda: self.check_clicked())
# TODO: Create a window that ask's for the spot it's specific color
'''def indication(self):
d = DialogOne()
d.exec_()'''
def check_clicked(self):
if self.btnSixtyPercent.text() == "60":
print("60%")
elif self.btnFivePercent.text() == "5":
print("5%")
elif self.btnTenPercent.text() == "10":
print("10%")
答案 0 :(得分:1)
当您将信号连接到插槽时,它会在生成信号时执行,如果您想使用发出信号的对象,则可以使用sender()
。不必使用{{ 1}}函数。
lambda
完整代码:
self.btnQuit.clicked.connect(self.close)
self.btnSixtyPercent.clicked.connect(self.check_clicked)
self.btnTenPercent.clicked.connect(self.check_clicked)
self.btnFivePercent.clicked.connect(self.check_clicked)
def check_clicked(self):
print("{}%".format(self.sender().text()