NameError: name 'self' is not defined
from PyQt5 import QtCore, QtGui, QtWidgets
import time
from configparser import ConfigParser
from threading import Thread
config = ConfigParser()
config.read("main.config")
timerTime = int(config["Time"]["timerTime"])
timerTime = int(list(str(timerTime))[0]) * 36000 + int(list(str(timerTime))[1]) * 3600 + int(list(str(timerTime))[2]) * 600 + int(list(str(timerTime))[3]) * 60 + int(list(str(timerTime))[4]) + int(list(str(timerTime))[5])
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.setEnabled(True)
Form.resize(300, 400)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Ignored, QtWidgets.QSizePolicy.Policy.Ignored)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
Form.setSizePolicy(sizePolicy)
Form.setMinimumSize(QtCore.QSize(300, 400))
Form.setMaximumSize(QtCore.QSize(300, 400))
self.btnStrStp = QtWidgets.QPushButton(Form)
self.btnStrStp.setGeometry(QtCore.QRect(5, 310, 290, 80))
font = QtGui.QFont()
font.setFamily("Gulim")
font.setPointSize(40)
self.btnStrStp.setFont(font)
self.btnStrStp.setObjectName("btnStrStp")
self.btnMnsH = QtWidgets.QPushButton(Form)
self.btnMnsH.setGeometry(QtCore.QRect(5, 220, 140, 80))
font = QtGui.QFont()
font.setFamily("Gulim")
font.setPointSize(100)
self.btnMnsH.setFont(font)
self.btnMnsH.setObjectName("btnMnsH")
self.btnPlsH = QtWidgets.QPushButton(Form)
self.btnPlsH.setGeometry(QtCore.QRect(155, 220, 140, 80))
font = QtGui.QFont()
font.setFamily("Gulim")
font.setPointSize(100)
self.btnPlsH.setFont(font)
self.btnPlsH.setObjectName("btnPlsH")
self.scrn = QtWidgets.QLabel(Form)
self.scrn.setGeometry(QtCore.QRect(5, 10, 290, 100))
font = QtGui.QFont()
font.setFamily("Gulim")
font.setPointSize(40)
font.setBold(False)
font.setItalic(False)
font.setUnderline(False)
font.setWeight(50)
font.setStrikeOut(False)
font.setKerning(False)
font.setStyleStrategy(QtGui.QFont.StyleStrategy.PreferDefault)
self.scrn.setFont(font)
self.scrn.setLayoutDirection(QtCore.Qt.LayoutDirection.LeftToRight)
self.scrn.setFrameShape(QtWidgets.QFrame.Shape.NoFrame)
self.scrn.setFrameShadow(QtWidgets.QFrame.Shadow.Plain)
self.scrn.setLineWidth(1)
self.scrn.setMidLineWidth(0)
self.scrn.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.scrn.setWordWrap(False)
self.scrn.setObjectName("scrn")
self.btnMnsM = QtWidgets.QPushButton(Form)
self.btnMnsM.setGeometry(QtCore.QRect(5, 130, 140, 80))
font = QtGui.QFont()
font.setFamily("Gulim")
font.setPointSize(100)
self.btnMnsM.setFont(font)
self.btnMnsM.setObjectName("btnMnsM")
self.btnPlsM = QtWidgets.QPushButton(Form)
self.btnPlsM.setGeometry(QtCore.QRect(155, 130, 140, 80))
font = QtGui.QFont()
font.setFamily("Gulim")
font.setPointSize(100)
self.btnPlsM.setFont(font)
self.btnPlsM.setObjectName("btnPlsM")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
self.tmrFunc()
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.btnStrStp.setText(_translate("Form", "Start/Stop"))
self.btnMnsH.setText(_translate("Form", "-"))
self.btnPlsH.setText(_translate("Form", "+"))
self.scrn.setText(_translate("Form", "00:00:00"))
self.btnMnsM.setText(_translate("Form", "-"))
self.btnPlsM.setText(_translate("Form", "+"))
def tmrFunc(self):
self.btnStrStp.clicked.connect(lambda: self.th0.start())
self.btnMnsH.clicked.connect(lambda: self.tmrMnsH())
self.btnPlsH.clicked.connect(lambda: self.tmrPlsH())
self.btnMnsM.clicked.connect(lambda: self.tmrMnsM())
self.btnPlsM.clicked.connect(lambda: self.tmrPlsM())
def tmrScreen(self):
while True:
self.scrn.setText(self.tmrTimer())
time.sleep(1)
def tmrTimer(self):
global timerTime
self.tmrSetTime = timerTime
self.tmrTimeH = int(time.strftime("%H")) * 3600
self.tmrTimeM = int(time.strftime("%M")) * 60
self.tmrTimeS = int(time.strftime("%S"))
self.tmrTime = self.tmrSetTime - (self.tmrTimeH + self.tmrTimeM + self.tmrTimeS)
self.tmrSetTimeH = str(self.tmrTime // 3600)
if int(self.tmrSetTimeH) < 10:
self.tmrSetTimeH = '0' + self.tmrSetTimeH
self.tmrSetTimeM = str(self.tmrTime % 3600 // 60)
if int(self.tmrSetTimeM) < 10:
self.tmrSetTimeM = '0' + self.tmrSetTimeM
self.tmrSetTimeS = str(self.tmrTime % 60)
if int(self.tmrSetTimeS) < 10:
self.tmrSetTimeS = '0' + self.tmrSetTimeS
return self.tmrSetTimeH + ':' + self.tmrSetTimeM + ':' + self.tmrSetTimeS
def tmrMnsH(self):
global timerTime
timerTime -= 3600
def tmrPlsH(self):
global timerTime
timerTime += 3600
def tmrMnsM(self):
global timerTime
timerTime -= 60
def tmrPlsM(self):
global timerTime
timerTime += 60
th0 = Thread(target=tmrScreen)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_Form()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())