无法使用pyqt5显示秒表

Can't display stop watch using pyqt5

我正在构建一个非常简单的 GUI,但我无法算出我的秒表。 我有两个不同的文件 - 一个用于 GUI 的变量,另一个文件具有所有功能。 我的目标是,一旦用户按下 "run" 按钮,计时器就会出现在小文本框上,每秒以 'hh:mm:ss' 的形式变化。 我所做的基本上是收集一些我认为适合我的脚本的信息和代码行,但我认为我有一些错误并且它不起作用(我试图改变一些东西,但我明白了每次都有不同的错误..)

这些是我的文件:

GUI 文件:

from PyQt5 import QtCore, QtGui, QtWidgets



 class Ui_MainWindow(object):
  def setupUi(self, MainWindow):
    MainWindow.setObjectName("MainWindow")
    MainWindow.resize(895, 422)
    self.centralwidget = QtWidgets.QWidget(MainWindow)
    self.centralwidget.setObjectName("centralwidget")


    self.timer=QtCore.QTimer(self.centralwidget)
    self.timer.timeout.connect(self.showTime)
    self.timer.start(1000)
    self.showTime(MainWindow)

    ###txtoutput = big window for text###
    self.txtoutput = QtWidgets.QTextBrowser(self.centralwidget)
    self.txtoutput.setGeometry(QtCore.QRect(150, 200, 471, 192))
    self.txtoutput.setObjectName("txtoutput")

    ###modeltype = droplist###
    self.modeltype = QtWidgets.QComboBox(self.centralwidget)
    self.modeltype.setGeometry(QtCore.QRect(50, 90, 69, 22))
    self.modeltype.setObjectName("modeltype")
    self.modeltype.addItem("")
    self.modeltype.addItem("")
    self.modeltype.addItem("")

    ###seriallbl = label above input window###
    self.seriallbl = QtWidgets.QLabel(self.centralwidget)
    self.seriallbl.setGeometry(QtCore.QRect(90, 30, 81, 16))
    self.seriallbl.setObjectName("seriallbl")

    ###getserialbtn = "Enter" button###
    self.getserialbtn = QtWidgets.QPushButton(self.centralwidget)
    self.getserialbtn.setGeometry(QtCore.QRect(210, 50, 75, 23))
    self.getserialbtn.setObjectName("getserialbtn")

    ###chuckrealeasebtn = "Chuck"/"Release" button###
    self.chuckrealeasebtn = QtWidgets.QPushButton(self.centralwidget)
    self.chuckrealeasebtn.setEnabled(False)
    self.chuckrealeasebtn.setGeometry(QtCore.QRect(50, 120, 75, 23))
    self.chuckrealeasebtn.setObjectName("chuckrealeasebtn")
    self.chuckrealeasebtn.setCheckable(True)

    ###runbtn = "Run" button###
    self.runbtn = QtWidgets.QPushButton(self.centralwidget)
    self.runbtn.setEnabled(False)
    self.runbtn.setGeometry(QtCore.QRect(580, 70, 91, 61))
    font = QtGui.QFont()
    font.setPointSize(28)
    font.setBold(True)
    font.setWeight(75)
    self.runbtn.setFont(font)
    self.runbtn.setCheckable(False)
    self.runbtn.setObjectName("runbtn")

    ###serialinput = Text box for serial # input###
    self.serialinput = QtWidgets.QTextEdit(self.centralwidget)
    self.serialinput.setGeometry(QtCore.QRect(50, 50, 151, 31))
    self.serialinput.setObjectName("serialinput")

    ###stopbtn = "Stop" button###
    self.stopbtn = QtWidgets.QPushButton(self.centralwidget)
    self.stopbtn.setGeometry(QtCore.QRect(680, 70, 91, 61))
    font = QtGui.QFont()
    font.setPointSize(28)
    font.setBold(True)
    font.setWeight(75)
    self.stopbtn.setFont(font)
    self.stopbtn.setObjectName("stopbtn")

    ###exitbtn = "Exit" button###
    self.exitbtn = QtWidgets.QPushButton(self.centralwidget)
    self.exitbtn.setGeometry(QtCore.QRect(740, 370, 75, 23))
    self.exitbtn.setObjectName("exitbtn")
    self.timelbl = QtWidgets.QLabel(self.centralwidget)
    self.timelbl.setGeometry(QtCore.QRect(320, 140, 47, 13))
    self.timelbl.setObjectName("timelbl")

    ###timertxt = label above timer window###
    self.timertxt = QtWidgets.QTextBrowser(self.centralwidget)
    self.timertxt.setGeometry(QtCore.QRect(260, 160, 141, 31))
    self.timertxt.setObjectName("timertxt")


    MainWindow.setCentralWidget(self.centralwidget)
    self.retranslateUi(MainWindow)
    QtCore.QMetaObject.connectSlotsByName(MainWindow)



def retranslateUi(self, MainWindow):
    _translate = QtCore.QCoreApplication.translate
    MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
    self.modeltype.setItemText(0, _translate("MainWindow", "Type 1"))
    self.modeltype.setItemText(1, _translate("MainWindow", "Type 2"))
    self.modeltype.setItemText(2, _translate("MainWindow", "Type 3"))
    self.seriallbl.setText(_translate("MainWindow", "Enter serial #"))
    self.getserialbtn.setText(_translate("MainWindow", "Enter"))
    self.chuckrealeasebtn.setText(_translate("MainWindow", "chuck"))
    self.runbtn.setText(_translate("MainWindow", "Run"))
    self.stopbtn.setText(_translate("MainWindow", "Stop"))
    self.exitbtn.setText(_translate("MainWindow", "Exit"))
    self.timelbl.setText(_translate("MainWindow", "Timer"))

还有我的主要:

from PyQt5 import QtWidgets, QtCore, QtGui
from mainwin import Ui_MainWindow


class ApplicationWindow(QtWidgets.QMainWindow):
  def __init__(self):
   super(ApplicationWindow, self).__init__()

   self.ui = Ui_MainWindow()
   self.ui.setupUi(self)   

   self.ui.exitbtn.clicked.connect(self.exitclicked)      
   self.ui.getserialbtn.clicked.connect(self.serialentered)
   self.ui.chuckrealeasebtn.clicked.connect(self.chuckclicked)
   self.ui.runbtn.clicked.connect(self.showTime)

###exitclicked = "Exit" button function###
def exitclicked(self):                                      
    self.close()


def showTime(self):
    time=self.ui.QTime.currentTime()
    text=self.ui.time.toString('hh:mm:ss')
    if(time.second()%2==0):
        text=text[:2]+ ' ' +text [3:]
    self.ui.txtoutput.append(text)


###chuckclicked = "Chuck"/"Release" button function###    
def chuckclicked(self):
    if self.ui.chuckrealeasebtn.isChecked():
        mytext = self.ui.serialinput.toPlainText()
        self.ui.chuckrealeasebtn.setText("Release")
        self.ui.getserialbtn.setEnabled(False)
        self.ui.runbtn.setEnabled(True)
        self.ui.txtoutput.append(mytext+" - is chucked, Ready to run")
    else:
        self.ui.chuckrealeasebtn.setText("Chuck")
        self.ui.txtoutput.clear()
        self.ui.chuckrealeasebtn.setEnabled(False)
        self.ui.getserialbtn.setEnabled(True)
        self.ui.runbtn.setEnabled(False)

###serialentered = function that checks if the serial # that was entered is found or not found in a certain list###    
def serialentered(self):
    serialnum = self.ui.serialinput.toPlainText()
    listnum=self.ui.modeltype.currentIndex()
    if (listnum==0):
        with open(r'C:\Users\hv_lab\Documents\python tests\Serial Numbers - Type 1.txt') as r1:
            if serialnum in r1.read():
                self.ui.txtoutput.append(serialnum+" - Serial was found in List 1")
                self.ui.chuckrealeasebtn.setEnabled(True)
            else:
                self.ui.txtoutput.append(serialnum+" - Serial was NOT found in List 1")
                self.ui.chuckrealeasebtn.setEnabled(False)
    elif (listnum==1):
        with open(r'C:\Users\hv_lab\Documents\python tests\Serial Numbers - Type 2.txt') as r2:
            if serialnum in r2.read():
                self.ui.txtoutput.append(serialnum+" - Serial was found in List 2")
                self.ui.chuckrealeasebtn.setEnabled(True)
            else:
                self.ui.txtoutput.append(serialnum+" - Serial was NOT found in List 2")
                self.ui.chuckrealeasebtn.setEnabled(False)
    elif (listnum==2):
        with open(r'C:\Users\hv_lab\Documents\python tests\Serial Numbers - Type 3.txt') as r3:
            if serialnum in r3.read():
                self.ui.txtoutput.append(serialnum+" - Serial was found in List 3")
                self.ui.chuckrealeasebtn.setEnabled(True)
            else:
                 self.ui.txtoutput.append(serialnum+" - Serial was NOT found in List 3")
                 self.ui.chuckrealeasebtn.setEnabled(False)



 def main():
  import sys
  app = QtWidgets.QApplication(sys.argv)
  application = ApplicationWindow()
  application.show()
  sys.exit(app.exec_())

if __name__ == "__main__":
 main()

所以我不确定这里到底出了什么问题 - 如果有人有任何我没有想出的想法,我会很高兴..

提前谢谢大家!

***我应该编辑我希望秒表从 00:00:00 开始并在我按下 "run" 按钮后每秒计数

切勿修改在 QT Designer 中创建的模块。 试一试:

from PyQt5 import QtCore, QtGui, QtWidgets


# from mainwin import Ui_MainWindow
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(895, 422)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")


# -       self.timer=QtCore.QTimer(self.centralwidget)
# -       self.timer.timeout.connect(self.showTime)
# -       self.timer.start(1000)
# -       self.showTime(MainWindow)

        ###txtoutput = big window for text###
        self.txtoutput = QtWidgets.QTextBrowser(self.centralwidget)
        self.txtoutput.setGeometry(QtCore.QRect(150, 200, 471, 192))
        self.txtoutput.setObjectName("txtoutput")

        ###modeltype = droplist###
        self.modeltype = QtWidgets.QComboBox(self.centralwidget)
        self.modeltype.setGeometry(QtCore.QRect(50, 90, 69, 22))
        self.modeltype.setObjectName("modeltype")
        self.modeltype.addItem("")
        self.modeltype.addItem("")
        self.modeltype.addItem("")

        ###seriallbl = label above input window###
        self.seriallbl = QtWidgets.QLabel(self.centralwidget)
        self.seriallbl.setGeometry(QtCore.QRect(90, 30, 81, 16))
        self.seriallbl.setObjectName("seriallbl")

        ###getserialbtn = "Enter" button###
        self.getserialbtn = QtWidgets.QPushButton(self.centralwidget)
        self.getserialbtn.setGeometry(QtCore.QRect(210, 50, 75, 23))
        self.getserialbtn.setObjectName("getserialbtn")

        ###chuckrealeasebtn = "Chuck"/"Release" button###
        self.chuckrealeasebtn = QtWidgets.QPushButton(self.centralwidget)
        self.chuckrealeasebtn.setEnabled(False)
        self.chuckrealeasebtn.setGeometry(QtCore.QRect(50, 120, 75, 23))
        self.chuckrealeasebtn.setObjectName("chuckrealeasebtn")
        self.chuckrealeasebtn.setCheckable(True)

        ###runbtn = "Run" button###
        self.runbtn = QtWidgets.QPushButton(self.centralwidget)
# -       self.runbtn.setEnabled(False)
        self.runbtn.setGeometry(QtCore.QRect(580, 70, 91, 61))
        font = QtGui.QFont()
        font.setPointSize(28)
        font.setBold(True)
        font.setWeight(75)
        self.runbtn.setFont(font)
        self.runbtn.setCheckable(False)
        self.runbtn.setObjectName("runbtn")

        ###serialinput = Text box for serial # input###
        self.serialinput = QtWidgets.QTextEdit(self.centralwidget)
        self.serialinput.setGeometry(QtCore.QRect(50, 50, 151, 31))
        self.serialinput.setObjectName("serialinput")

        ###stopbtn = "Stop" button###
        self.stopbtn = QtWidgets.QPushButton(self.centralwidget)
        self.stopbtn.setGeometry(QtCore.QRect(680, 70, 91, 61))
        font = QtGui.QFont()
        font.setPointSize(28)
        font.setBold(True)
        font.setWeight(75)
        self.stopbtn.setFont(font)
        self.stopbtn.setObjectName("stopbtn")

        ###exitbtn = "Exit" button###
        self.exitbtn = QtWidgets.QPushButton(self.centralwidget)
        self.exitbtn.setGeometry(QtCore.QRect(740, 370, 75, 23))
        self.exitbtn.setObjectName("exitbtn")
        self.timelbl = QtWidgets.QLabel(self.centralwidget)
        self.timelbl.setGeometry(QtCore.QRect(320, 140, 47, 13))
        self.timelbl.setObjectName("timelbl")

        ###timertxt = label above timer window###
        self.timertxt = QtWidgets.QTextBrowser(self.centralwidget)
        self.timertxt.setGeometry(QtCore.QRect(260, 160, 141, 31))
        self.timertxt.setObjectName("timertxt")


        MainWindow.setCentralWidget(self.centralwidget)
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)



    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.modeltype.setItemText(0, _translate("MainWindow", "Type 1"))
        self.modeltype.setItemText(1, _translate("MainWindow", "Type 2"))
        self.modeltype.setItemText(2, _translate("MainWindow", "Type 3"))
        self.seriallbl.setText(_translate("MainWindow", "Enter serial #"))
        self.getserialbtn.setText(_translate("MainWindow", "Enter"))
        self.chuckrealeasebtn.setText(_translate("MainWindow", "chuck"))
        self.runbtn.setText(_translate("MainWindow", "Run"))
        self.stopbtn.setText(_translate("MainWindow", "Stop"))
        self.exitbtn.setText(_translate("MainWindow", "Exit"))
        self.timelbl.setText(_translate("MainWindow", "Timer"))


class ApplicationWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(ApplicationWindow, self).__init__()

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)   

        self.ui.exitbtn.clicked.connect(self.exitclicked)      
        self.ui.getserialbtn.clicked.connect(self.serialentered)
        self.ui.chuckrealeasebtn.clicked.connect(self.chuckclicked)
        self.ui.runbtn.clicked.connect(self.onClick_runbtn)         # - (self.showTime)

        self.timer = QtCore.QTimer(self)                            # +++
        self.timer.timeout.connect(self.showTime)                   # +++

    ###exitclicked = "Exit" button function###
    def exitclicked(self):                                      
        self.close()

    def onClick_runbtn(self):                                       # +++
        self.timer.start(1000)                                      # +++

    def showTime(self):
        time = QtCore.QTime.currentTime()                           # - self.ui.QTime.currentTime()
        text = time.toString('hh:mm:ss')                            # - self.ui.time.toString('hh:mm:ss')
        if(time.second()%2==0):
            text = text[:2]+ ' ' +text [3:]
#        self.ui.txtoutput.append(text)
        self.ui.timelbl.setText(text)

    ###chuckclicked = "Chuck"/"Release" button function###    
    def chuckclicked(self):
        if self.ui.chuckrealeasebtn.isChecked():
            mytext = self.ui.serialinput.toPlainText()
            self.ui.chuckrealeasebtn.setText("Release")
            self.ui.getserialbtn.setEnabled(False)
            self.ui.runbtn.setEnabled(True)
            self.ui.txtoutput.append(mytext+" - is chucked, Ready to run")
        else:
            self.ui.chuckrealeasebtn.setText("Chuck")
            self.ui.txtoutput.clear()
            self.ui.chuckrealeasebtn.setEnabled(False)
            self.ui.getserialbtn.setEnabled(True)
            self.ui.runbtn.setEnabled(False)

    ###serialentered = function that checks if the serial # that was entered is found or not found in a certain list###    
    def serialentered(self):
        serialnum = self.ui.serialinput.toPlainText()
        listnum=self.ui.modeltype.currentIndex()
        if (listnum==0):
            with open(r'C:\Users\hv_lab\Documents\python tests\Serial Numbers - Type 1.txt') as r1:
                if serialnum in r1.read():
                    self.ui.txtoutput.append(serialnum+" - Serial was found in List 1")
                    self.ui.chuckrealeasebtn.setEnabled(True)
                else:
                    self.ui.txtoutput.append(serialnum+" - Serial was NOT found in List 1")
                    self.ui.chuckrealeasebtn.setEnabled(False)
        elif (listnum==1):
            with open(r'C:\Users\hv_lab\Documents\python tests\Serial Numbers - Type 2.txt') as r2:
                if serialnum in r2.read():
                    self.ui.txtoutput.append(serialnum+" - Serial was found in List 2")
                    self.ui.chuckrealeasebtn.setEnabled(True)
                else:
                    self.ui.txtoutput.append(serialnum+" - Serial was NOT found in List 2")
                    self.ui.chuckrealeasebtn.setEnabled(False)
        elif (listnum==2):
            with open(r'C:\Users\hv_lab\Documents\python tests\Serial Numbers - Type 3.txt') as r3:
                if serialnum in r3.read():
                    self.ui.txtoutput.append(serialnum+" - Serial was found in List 3")
                    self.ui.chuckrealeasebtn.setEnabled(True)
                else:
                     self.ui.txtoutput.append(serialnum+" - Serial was NOT found in List 3")
                     self.ui.chuckrealeasebtn.setEnabled(False)



if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    application = ApplicationWindow()
    application.show()
    sys.exit(app.exec_())


更新

why shouldnt I never edit a module created in QT designer?

自己想想如果你想改变你的设计会发生什么。你会记住很长一段时间你需要做出什么样的改变...

I want my stopwatch to start from 0, and count up every second. Is there a way to do that or I can only show current time?

from PyQt5 import QtCore, QtGui, QtWidgets
import time                                                            # +++

# from mainwin import Ui_MainWindow
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(895, 422)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        ###txtoutput = big window for text###
        self.txtoutput = QtWidgets.QTextBrowser(self.centralwidget)
        self.txtoutput.setGeometry(QtCore.QRect(150, 200, 471, 192))
        self.txtoutput.setObjectName("txtoutput")
        ###modeltype = droplist###
        self.modeltype = QtWidgets.QComboBox(self.centralwidget)
        self.modeltype.setGeometry(QtCore.QRect(50, 90, 69, 22))
        self.modeltype.setObjectName("modeltype")
        self.modeltype.addItem("")
        self.modeltype.addItem("")
        self.modeltype.addItem("")
        ###seriallbl = label above input window###
        self.seriallbl = QtWidgets.QLabel(self.centralwidget)
        self.seriallbl.setGeometry(QtCore.QRect(90, 30, 81, 16))
        self.seriallbl.setObjectName("seriallbl")
        ###getserialbtn = "Enter" button###
        self.getserialbtn = QtWidgets.QPushButton(self.centralwidget)
        self.getserialbtn.setGeometry(QtCore.QRect(210, 50, 75, 23))
        self.getserialbtn.setObjectName("getserialbtn")
        ###chuckrealeasebtn = "Chuck"/"Release" button###
        self.chuckrealeasebtn = QtWidgets.QPushButton(self.centralwidget)
        self.chuckrealeasebtn.setEnabled(False)
        self.chuckrealeasebtn.setGeometry(QtCore.QRect(50, 120, 75, 23))
        self.chuckrealeasebtn.setObjectName("chuckrealeasebtn")
        self.chuckrealeasebtn.setCheckable(True)
        ###runbtn = "Run" button###
        self.runbtn = QtWidgets.QPushButton(self.centralwidget)
# -       self.runbtn.setEnabled(False)
        self.runbtn.setGeometry(QtCore.QRect(580, 70, 91, 61))
        font = QtGui.QFont()
        font.setPointSize(28)
        font.setBold(True)
        font.setWeight(75)
        self.runbtn.setFont(font)
        self.runbtn.setCheckable(False)
        self.runbtn.setObjectName("runbtn")
        ###serialinput = Text box for serial # input###
        self.serialinput = QtWidgets.QTextEdit(self.centralwidget)
        self.serialinput.setGeometry(QtCore.QRect(50, 50, 151, 31))
        self.serialinput.setObjectName("serialinput")
        ###stopbtn = "Stop" button###
        self.stopbtn = QtWidgets.QPushButton(self.centralwidget)
        self.stopbtn.setGeometry(QtCore.QRect(680, 70, 91, 61))
        font = QtGui.QFont()
        font.setPointSize(28)
        font.setBold(True)
        font.setWeight(75)
        self.stopbtn.setFont(font)
        self.stopbtn.setObjectName("stopbtn")
        ###exitbtn = "Exit" button###
        self.exitbtn = QtWidgets.QPushButton(self.centralwidget)
        self.exitbtn.setGeometry(QtCore.QRect(740, 370, 75, 23))
        self.exitbtn.setObjectName("exitbtn")
        self.timelbl = QtWidgets.QLabel(self.centralwidget)
        self.timelbl.setGeometry(QtCore.QRect(260, 140, 147, 23))         # +
        self.timelbl.setObjectName("timelbl")
        ###timertxt = label above timer window###
        self.timertxt = QtWidgets.QTextBrowser(self.centralwidget)
        self.timertxt.setGeometry(QtCore.QRect(260, 160, 141, 31))
        self.timertxt.setObjectName("timertxt")

        MainWindow.setCentralWidget(self.centralwidget)
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.modeltype.setItemText(0, _translate("MainWindow", "Type 1"))
        self.modeltype.setItemText(1, _translate("MainWindow", "Type 2"))
        self.modeltype.setItemText(2, _translate("MainWindow", "Type 3"))
        self.seriallbl.setText(_translate("MainWindow", "Enter serial #"))
        self.getserialbtn.setText(_translate("MainWindow", "Enter"))
        self.chuckrealeasebtn.setText(_translate("MainWindow", "chuck"))
        self.runbtn.setText(_translate("MainWindow", "Run"))
        self.stopbtn.setText(_translate("MainWindow", "Stop"))
        self.exitbtn.setText(_translate("MainWindow", "Exit"))
        self.timelbl.setText(_translate("MainWindow", "Timer"))


class ApplicationWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(ApplicationWindow, self).__init__()

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)   

        self.ui.exitbtn.clicked.connect(self.exitclicked)      
        self.ui.getserialbtn.clicked.connect(self.serialentered)
        self.ui.chuckrealeasebtn.clicked.connect(self.chuckclicked)
        self.ui.runbtn.clicked.connect(self.onClick_runbtn)            # + self.onClick_runbtn 

### VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

        self.timer = QtCore.QTimer(self)                            
        self.timer.timeout.connect(self.showTime)                   
        self.time = 0
        self.timeInterval = 1000

    def onClick_runbtn(self):                                       
        self.timer.start(self.timeInterval)                                      
        self.timeViewer = QtWidgets.QLCDNumber(self)
        self.timeViewer.setGeometry(QtCore.QRect(280, 80, 100, 45))
        self.timeViewer.show()

    def showTime(self):  
        self.time += 1
        self.settimer(self.time)
        ##print(self.time)

    def settimer(self, int):
        self.time = int
        self.timeViewer.display(self.time)
        if self.timeInterval == 1000:
            self.ui.timelbl.setText(time.strftime('%H hour %M minute %S second',time.gmtime(self.time)))

### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^       

    ###exitclicked = "Exit" button function###
    def exitclicked(self):                                      
        self.close()        

    ###chuckclicked = "Chuck"/"Release" button function###    
    def chuckclicked(self):
        if self.ui.chuckrealeasebtn.isChecked():
            mytext = self.ui.serialinput.toPlainText()
            self.ui.chuckrealeasebtn.setText("Release")
            self.ui.getserialbtn.setEnabled(False)
            self.ui.runbtn.setEnabled(True)
            self.ui.txtoutput.append(mytext+" - is chucked, Ready to run")
        else:
            self.ui.chuckrealeasebtn.setText("Chuck")
            self.ui.txtoutput.clear()
            self.ui.chuckrealeasebtn.setEnabled(False)
            self.ui.getserialbtn.setEnabled(True)
            self.ui.runbtn.setEnabled(False)

    ###serialentered = function that checks if the serial # that was entered is found or not found in a certain list###    
    def serialentered(self):
        serialnum = self.ui.serialinput.toPlainText()
        listnum=self.ui.modeltype.currentIndex()
        if (listnum==0):
            with open(r'C:\Users\hv_lab\Documents\python tests\Serial Numbers - Type 1.txt') as r1:
                if serialnum in r1.read():
                    self.ui.txtoutput.append(serialnum+" - Serial was found in List 1")
                    self.ui.chuckrealeasebtn.setEnabled(True)
                else:
                    self.ui.txtoutput.append(serialnum+" - Serial was NOT found in List 1")
                    self.ui.chuckrealeasebtn.setEnabled(False)
        elif (listnum==1):
            with open(r'C:\Users\hv_lab\Documents\python tests\Serial Numbers - Type 2.txt') as r2:
                if serialnum in r2.read():
                    self.ui.txtoutput.append(serialnum+" - Serial was found in List 2")
                    self.ui.chuckrealeasebtn.setEnabled(True)
                else:
                    self.ui.txtoutput.append(serialnum+" - Serial was NOT found in List 2")
                    self.ui.chuckrealeasebtn.setEnabled(False)
        elif (listnum==2):
            with open(r'C:\Users\hv_lab\Documents\python tests\Serial Numbers - Type 3.txt') as r3:
                if serialnum in r3.read():
                    self.ui.txtoutput.append(serialnum+" - Serial was found in List 3")
                    self.ui.chuckrealeasebtn.setEnabled(True)
                else:
                     self.ui.txtoutput.append(serialnum+" - Serial was NOT found in List 3")
                     self.ui.chuckrealeasebtn.setEnabled(False)


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    application = ApplicationWindow()
    application.show()
    sys.exit(app.exec_())