所以我正在pyqt5中编程,我有一个函数可以捕获所有已单击的按钮,所以问题在于该函数包含if语句,如
self.bo.clicked:
blah blah blah
等大约十二个按钮, 所以问题是,一旦单击按钮,其.clicked值就会自动永久变为True,并且如果以前已经单击了不同的按钮,则所有if语句都将被触发,我想知道是否有任何方法可以撤消.clicked财产?
我尝试过的是:
if self.b0.clicked:
self.bo.setEnabled(False)
self.bo.setEnabled(True)
#attempting to reset the button.
但是那是行不通的,一旦一个按钮被“单击”,当我单击另一个按钮时,它们都会自动启动。 我对此有些陌生,所以请帮助我。或者也许解释另一种方式来做到这一点? 请,谢谢!
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'yevsCalcUi.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
self.work = []
self.operators = []
self.wrking = 0
self.blin = 0
MainWindow.setObjectName("MainWindow")
MainWindow.resize(350, 300)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout_4 = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout_4.setObjectName("gridLayout_4")
self.frame_4 = QtWidgets.QFrame(self.centralwidget)
self.frame_4.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_4.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_4.setObjectName("frame_4")
self.gridLayout_5 = QtWidgets.QGridLayout(self.frame_4)
self.gridLayout_5.setObjectName("gridLayout_5")
self.frame = QtWidgets.QFrame(self.frame_4)
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.gridLayout_3 = QtWidgets.QGridLayout(self.frame)
self.gridLayout_3.setObjectName("gridLayout_3")
self.frame_3 = QtWidgets.QFrame(self.frame)
self.frame_3.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_3.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_3.setObjectName("frame_3")
self.gridLayout_2 = QtWidgets.QGridLayout(self.frame_3)
self.gridLayout_2.setObjectName("gridLayout_2")
self.numbers = QtWidgets.QLabel(self.frame_3)
self.numbers.setObjectName("numbers")
self.numbers.setText("blin")
self.gridLayout_2.addWidget(self.numbers, 0, 0, 1, 1)
self.gridLayout_3.addWidget(self.frame_3, 0, 0, 1, 1)
self.frame_2 = QtWidgets.QFrame(self.frame)
self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_2.setObjectName("frame_2")
self.gridLayout = QtWidgets.QGridLayout(self.frame_2)
self.gridLayout.setObjectName("gridLayout")
self.b3 = QtWidgets.QPushButton(self.frame_2)
self.b3.setObjectName("b3")
self.gridLayout.addWidget(self.b3, 3, 2, 1, 1)
self.bac = QtWidgets.QPushButton(self.frame_2)
self.bac.setObjectName("bac")
self.gridLayout.addWidget(self.bac, 0, 0, 1, 1)
self.bmul = QtWidgets.QPushButton(self.frame_2)
self.bmul.setObjectName("bmul")
self.gridLayout.addWidget(self.bmul, 0, 3, 1, 1)
self.splitter_3 = QtWidgets.QSplitter(self.frame_2)
self.splitter_3.setOrientation(QtCore.Qt.Horizontal)
self.splitter_3.setObjectName("splitter_3")
self.b7 = QtWidgets.QPushButton(self.splitter_3)
self.b7.setObjectName("b7")
self.b8 = QtWidgets.QPushButton(self.splitter_3)
self.b8.setObjectName("b8")
self.b9 = QtWidgets.QPushButton(self.splitter_3)
self.b9.setObjectName("b9")
self.bmin = QtWidgets.QPushButton(self.splitter_3)
self.bmin.setObjectName("bmin")
self.gridLayout.addWidget(self.splitter_3, 1, 0, 1, 4)
self.bd = QtWidgets.QPushButton(self.frame_2)
self.bd.setObjectName("bd")
self.gridLayout.addWidget(self.bd, 4, 2, 1, 1)
self.bdiv = QtWidgets.QPushButton(self.frame_2)
self.bdiv.setObjectName("bdiv")
self.gridLayout.addWidget(self.bdiv, 0, 2, 1, 1)
self.b1 = QtWidgets.QPushButton(self.frame_2)
self.b1.setObjectName("b1")
self.gridLayout.addWidget(self.b1, 3, 0, 1, 1)
self.splitter_2 = QtWidgets.QSplitter(self.frame_2)
self.splitter_2.setOrientation(QtCore.Qt.Horizontal)
self.splitter_2.setObjectName("splitter_2")
self.b4 = QtWidgets.QPushButton(self.splitter_2)
self.b4.setObjectName("b4")
self.b5 = QtWidgets.QPushButton(self.splitter_2)
self.b5.setObjectName("b5")
self.b6 = QtWidgets.QPushButton(self.splitter_2)
self.b6.setObjectName("b6")
self.bplu = QtWidgets.QPushButton(self.splitter_2)
self.bplu.setObjectName("bplu")
self.gridLayout.addWidget(self.splitter_2, 2, 0, 1, 4)
self.b2 = QtWidgets.QPushButton(self.frame_2)
self.b2.setObjectName("b2")
self.gridLayout.addWidget(self.b2, 3, 1, 1, 1)
self.bpm = QtWidgets.QPushButton(self.frame_2)
self.bpm.setObjectName("bpm")
self.gridLayout.addWidget(self.bpm, 0, 1, 1, 1)
self.beq = QtWidgets.QPushButton(self.frame_2)
self.beq.setMinimumSize(QtCore.QSize(0, 25))
self.beq.setObjectName("beq")
self.gridLayout.addWidget(self.beq, 3, 3, 1, 1)
self.gridLayout_3.addWidget(self.frame_2, 1, 0, 1, 1)
self.gridLayout_5.addWidget(self.frame, 0, 0, 1, 1)
spacerItem = QtWidgets.QSpacerItem(572, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout_5.addItem(spacerItem, 0, 1, 1, 1)
spacerItem1 = QtWidgets.QSpacerItem(20, 292, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.gridLayout_5.addItem(spacerItem1, 1, 0, 1, 1)
self.gridLayout_4.addWidget(self.frame_4, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 997, 22))
self.menubar.setObjectName("menubar")
self.b0 = QtWidgets.QPushButton(self.frame_2)
self.b0.setObjectName("b0")
numbas = []
self.b0.setProperty('0', numbas)
self.gridLayout.addWidget(self.b0, 4, 0, 1, 2)
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.i = 0
self.b0.clicked.connect(self.changeLabel)
self.bplu.clicked.connect(self.changeLabel)
def changeLabel(self):
self.blin = self.blin + 1
print("blin")
self.numbers.setText("0")
if self.b0.clicked:
print("okay now that is Legit!")
self.b0.setEnabled(False)
self.b0.setEnabled(True)
self.numbers.setText("0")
if self.bplu.clicked:
self.blin = 0
print(self.blin)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.numbers.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-size:24pt;\">blinulator</span></p></body></html>"))
self.b3.setText(_translate("MainWindow", "3"))
self.bac.setText(_translate("MainWindow", "AC"))
self.bmul.setText(_translate("MainWindow", "*"))
self.b7.setText(_translate("MainWindow", "7"))
self.b8.setText(_translate("MainWindow", "8"))
self.b9.setText(_translate("MainWindow", "9"))
self.bmin.setText(_translate("MainWindow", "-"))
self.bd.setText(_translate("MainWindow", "."))
self.bdiv.setText(_translate("MainWindow", "/"))
self.b0.setText(_translate("MainWindow", "0"))
self.b1.setText(_translate("MainWindow", "1"))
self.b4.setText(_translate("MainWindow", "4"))
self.b5.setText(_translate("MainWindow", "5"))
self.b6.setText(_translate("MainWindow", "6"))
self.bplu.setText(_translate("MainWindow", "+"))
self.b2.setText(_translate("MainWindow", "2"))
self.bpm.setText(_translate("MainWindow", "+/-"))
self.beq.setText(_translate("MainWindow", "="))
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())