我正在构建一个非常简单的GUI,但无法管理秒表。 我有两个不同的文件-一个用于GUI的变量,另一个具有所有功能。 我的目标是,一旦用户按下“运行”按钮,计时器就会出现在小文本框中,以“ 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开始,并在我按下“运行”按钮后每秒计数一次。
答案 0 :(得分:1)
请勿修改在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_())
更新
为什么我从不编辑在QT设计器中创建的模块?
请自己考虑一下,如果您想更改设计,将会发生什么。您会记住很长时间,您需要进行哪些更改...
我希望我的秒表从0开始,并每秒计数一次。有没有办法做到这一点,或者我只能显示当前时间?
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_())