from PyQt5 import QtCore,QtGui,QtWidgets,uic import sys class Begin(QtWidgets.QMainWindow): def __init__(self): super(Begin, self).__init__() self.ui = uic.loadUi("begin.ui") self.lines = 0 self.sec = 15000 self.mark = 0 self.mass2 = [] self.mass = [] self.vid = '' self.ui.lb1.setVisible(0) self.ui.lb2.setVisible(0) self.ui.lb3.setVisible(0) self.ui.lb4.setVisible(0) self.ui.lb5.setVisible(0) self.ui.lb6.setVisible(0) self.ui.lb7.setVisible(0) self.ui.lb8.setVisible(0) self.ui.lb9.setVisible(0) self.pixmap = QtGui.QPixmap("begin.ico") self.pixmap1 = QtGui.QPixmap("false.ico") self.timer = QtCore.QTimer() self.timer.timeout.connect(self.on_timeout) self.ui.a.clicked.connect(self.a_click) self.ui.b.clicked.connect(self.b_click) self.ui.c.clicked.connect(self.c_click) self.ui.d.clicked.connect(self.d_click) self.ui.open.clicked.connect(self.open_file) self.ui.next.clicked.connect(self.next) self.ui.open2.clicked.connect(self.open_file2) self.ui.next2.clicked.connect(self.next2) self.ui.next3.clicked.connect(self.next3) self.ui.next4.clicked.connect(self.next4) self.ui.show() def on_timeout(self): self.sec -= 1 self.ui.lcd3.display(self.sec % 60) self.ui.lcd2.display((self.sec // 60) % 60) self.ui.lcd1.display(self.sec // 3600) if self.sec < 0: self.timer.stop() def open_file(self): f1 = open('test5.txt', 'r') F1 = open('temp.txt', 'w') for i in f1: F1.writelines(i) f1.close() F1.close() F1 = open('temp.txt', 'r') s = [] line = F1.readlines() s.append(line[0]) s.append(line[1]) s.append(line[2]) s.append(line[3]) self.ask = int(s[0]) self.ask2 = int(s[1]) self.ask3 = int(s[2]) self.ask4 = int(s[3]) F1.close() with open('temp.txt') as f: a = f.readlines() with open('temp.txt', 'w') as f: f.writelines(a[4:-1]) self.fileName = 'temp.txt' F = open(self.fileName) self.Data = F.readlines() self.lines = len(self.Data) F.close() self.currentLine = 0 self.getTest() self.timer.start(1000) def getTest(self): while self.currentLine < self.lines: line = self.Data[self.currentLine] self.ui.asked.append(line.rstrip()) if line.rstrip() == "*": line = self.Data[self.currentLine + 1].rstrip() self.ui.a.setText(line) line = self.Data[self.currentLine + 2].rstrip() self.ui.b.setText(line) line = self.Data[self.currentLine + 3].rstrip() self.ui.c.setText(line) line = self.Data[self.currentLine + 4].rstrip() self.ui.d.setText(line) line = self.Data[self.currentLine + 5].rstrip() self.vid = line print(self.Data[self.currentLine + 6].rstrip()) self.currentLine += 7 self.ask-=1 break self.currentLine += 1 def next(self): print(self.lines) print(self.currentLine) self.ui.asked.setText(" ") self.ui.a.setText(" ") self.ui.b.setText(" ") self.ui.c.setText(" ") self.ui.d.setText(" ") self.getTest() def open_file2(self): self.mark2 = 0 self.ui.lb1.setVisible(1) self.ui.lb2.setVisible(1) self.ui.lb3.setVisible(1) self.ui.lb4.setVisible(1) self.ui.lb5.setVisible(1) self.ui.lb6.setVisible(1) self.ui.lb7.setVisible(1) self.ui.lb8.setVisible(1) self.ui.lb9.setVisible(1) self.ui.a.setVisible(0) self.ui.b.setVisible(0) self.ui.c.setVisible(0) self.ui.d.setVisible(0) self.currentLine = 0 self.fileName = 'temp.txt' F = open(self.fileName) self.Data = F.readlines() self.lines = len(self.Data) F.close() self.currentLine = 0 self.getTest2() def getTest2(self): while self.currentLine < self.lines: line = self.Data[self.currentLine] self.ui.asked.append(line.rstrip()) if line.rstrip() == "**": line = self.Data[self.currentLine + 1].rstrip() self.ui.lb1.setText(line) line = self.Data[self.currentLine + 2].rstrip() self.ui.lb2.setText(line) line = self.Data[self.currentLine + 3].rstrip() self.ui.lb3.setText(line) line = self.Data[self.currentLine + 4].rstrip() self.ui.lb4.setText(line) line = self.Data[self.currentLine + 5].rstrip() self.ui.lb5.setText(line) line = self.Data[self.currentLine + 6].rstrip() self.ui.lb6.setText(line) line = self.Data[self.currentLine + 7].rstrip() self.ui.lb7.setText(line) line = self.Data[self.currentLine + 8].rstrip() self.ui.lb8.setText(line) line = self.Data[self.currentLine + 9].rstrip() self.ui.lb9.setText(line) line = self.Data[self.currentLine + 10].rstrip() self.vid = line print(self.Data[self.currentLine + 11].rstrip()) self.currentLine += 12 self.ask3-=1 break self.currentLine += 1 def next2(self): if self.ask3 == 0: self.rez = 'A' + str(self.ui.sb1.value()) + 'B' + str(self.ui.sb2.value()) + 'C' + str( self.ui.sb3.value()) + 'D' + str(self.ui.sb4.value()) + 'F' + str(self.ui.sb5.value()) if self.rez[0:2] == self.vid[0:2]: self.mark2 += 1 if self.rez[2:4] == self.vid[2:4]: self.mark2 += 1 if self.rez[4:6] == self.vid[4:6]: self.mark2 += 1 if self.rez[6:8] == self.vid[6:8]: self.mark2 += 1 if self.rez[8:10] == self.vid[8:10]: self.mark2 += 1 self.ui.asked.setText(" ") self.qustoins2() self.open_file4() else: self.rez = 'A' + str(self.ui.sb1.value()) + 'B' + str(self.ui.sb2.value()) + 'C' + str( self.ui.sb3.value()) + 'D' + str(self.ui.sb4.value()) + 'F' + str(self.ui.sb5.value()) if self.rez[0:2] == self.vid[0:2]: self.mark2 += 1 if self.rez[2:4] == self.vid[2:4]: self.mark2 += 1 if self.rez[4:6] == self.vid[4:6]: self.mark2 += 1 if self.rez[6:8] == self.vid[6:8]: self.mark2 += 1 if self.rez[8:10] == self.vid[8:10]: self.mark2 += 1 self.ui.asked.setText(" ") self.getTest2() def open_file3(self): self.mark3 = 0 self.vid2 = [] self.ui.a.setVisible(0) self.ui.b.setVisible(0) self.ui.c.setVisible(0) self.ui.d.setVisible(0) self.currentLine = 0 self.fileName = 'temp.txt' F = open(self.fileName) self.Data = F.readlines() self.lines = len(self.Data) F.close() self.currentLine = 0 self.getTest3() def getTest3(self): while self.currentLine < self.lines: line = self.Data[self.currentLine] self.ui.asked.append(line.rstrip()) if line.rstrip() == "***": line = self.Data[self.currentLine + 1].rstrip() self.ui.cb1.setText(line) line = self.Data[self.currentLine + 2].rstrip() self.ui.cb2.setText(line) line = self.Data[self.currentLine + 3].rstrip() self.ui.cb3.setText(line) line = self.Data[self.currentLine + 4].rstrip() self.ui.cb4.setText(line) line = self.Data[self.currentLine + 5].rstrip() self.ui.cb5.setText(line) line = self.Data[self.currentLine + 6].rstrip() self.ui.cb6.setText(line) line = self.Data[self.currentLine + 7].rstrip() self.vid2.append(line) line = self.Data[self.currentLine + 8].rstrip() self.vid2.append(line) print(self.Data[self.currentLine + 9].rstrip()) self.currentLine += 10 self.ask2-=1 break self.currentLine += 1 else: self.qustoins2() self.open_file2() def next3(self): if self.ask2 == 0: self.ui.asked.setText(" ") self.qustoins2() self.open_file2() else: self.ui.asked.setText(" ") print(self.lines) print(self.currentLine) if self.ui.cb1.isChecked(): self.mass2.append("A") if self.ui.cb2.isChecked(): self.mass2.append("B") if self.ui.cb3.isChecked(): self.mass2.append("C") if self.ui.cb4.isChecked(): self.mass2.append("D") if self.ui.cb5.isChecked(): self.mass2.append("E") if self.ui.cb6.isChecked(): self.mass2.append("F") for i in range(0, 2): for j in range(0, 2): if self.vid2[i] == self.mass2[j]: self.mark3 += 1 self.mass2.clear() self.ui.cb1.setChecked(0) self.ui.cb2.setChecked(0) self.ui.cb3.setChecked(0) self.ui.cb4.setChecked(0) self.ui.cb5.setChecked(0) self.ui.cb6.setChecked(0) self.getTest3() def open_file4(self): self.mark4 = 0 self.vid3 = '' self.currentLine = 0 self.fileName = 'temp.txt' F = open(self.fileName) self.Data = F.readlines() self.lines = len(self.Data) F.close() self.currentLine = 0 self.getTest4() def getTest4(self): while self.currentLine < self.lines: line = self.Data[self.currentLine] self.ui.asked.append(line.rstrip()) if line.rstrip() == "****": line = self.Data[self.currentLine + 1].rstrip() self.vid3 = line print(self.Data[self.currentLine + 2].rstrip()) self.currentLine += 3 self.ask4-=1 break self.currentLine += 1 else: self.qustoins2() self.open_file4() def next4(self): if self.ask4 == 0: if self.vid3 == self.ui.le.text(): self.mark4 += 1 sum1 = self.mark+self.mark2+self.mark3+self.mark4 print(sum1) QtWidgets.QMessageBox.information(window, "Finish", 'Marks' + str(self.mark), buttons=QtWidgets.QMessageBox.Close, defaultButton=QtWidgets.QMessageBox.Close) self.timer.stop() app.quit() return False else: if self.vid3 == self.ui.le.text(): self.mark4 += 1 self.ui.asked.setText(" ") self.getTest4() def qustoins2(self): with open('temp.txt') as f: a = f.readlines() with open('temp.txt', 'w') as f: f.writelines(a[self.currentLine:-1]) def a_click(self): if self.vid == 'A': self.mark+=1 self.ui.lb.setPixmap(self.pixmap) if self.ask == 0: self.qustoins2() self.ui.asked.setText(" ") self.open_file3() else: self.next() else: self.ui.lb.setPixmap(self.pixmap1) if self.ask == 0: self.qustoins2() self.ui.asked.setText(" ") self.open_file3() else: self.next() def b_click(self): if self.vid == 'B': self.mark += 1 self.ui.lb.setPixmap(self.pixmap) if self.ask == 0: self.qustoins2() self.ui.asked.setText(" ") self.open_file3() else: self.next() else: self.ui.lb.setPixmap(self.pixmap1) if self.ask == 0: self.qustoins2() self.ui.asked.setText(" ") self.open_file3() else: self.next() def c_click(self): if self.vid == 'C': self.mark += 1 self.ui.lb.setPixmap(self.pixmap) if self.ask == 0: self.qustoins2() self.ui.asked.setText(" ") self.open_file3() else: self.next() else: self.ui.lb.setPixmap(self.pixmap1) if self.ask == 0: self.qustoins2() self.ui.asked.setText(" ") self.open_file3() else: self.next() def d_click(self): if self.vid == 'D': self.mark += 1 self.ui.lb.setPixmap(self.pixmap) if self.ask == 0: self.qustoins2() self.ui.asked.setText(" ") self.open_file3() else: self.next() else: self.ui.lb.setPixmap(self.pixmap1) if self.ask == 0: self.qustoins2() self.ui.asked.setText(" ") self.open_file3() else: self.next() if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) window = Begin() sys.exit(app.exec())