I am new to pyqt5. I have to make a quiz application, in which total time will be equal to total number of questions. I have get the total time, but I don't know that how to show that time while displaying the quiz. I have tried some code but it is freezing the user interface.
I have this timer code which is freezing the GUI
def Time(self):
self.seconds = self.total_time * 60
for self.remaining in range(self.seconds, 0, -1):
self.minutes = 0
self.seconds = self.remaining
if self.remaining > 60:
self.minutes = int(self.seconds / 60)
self.seconds = int(self.seconds % 60)
else:
self.seconds = self.remaining
self._time = "{:2d} minutes {:2d} seconds remaining.".format(self.minutes, self.seconds)
self.disp_time_label.setText(self._time)
time.sleep(1)
self.disp_time_label.setText("Time Ends")
Fetching total time from here
def fetchTotalTime_and_TotalMarks(self):
query = "SELECT q_id FROM EntranceExam_Quiz_Application.dbo.tbl_questions"
conn = createConnection()
connection = conn.cursor()
connection.execute(query)
rows = connection.fetchall()
conn.commit()
self.q_no_list = []
self.q_row_len = []
for i in rows:
self.q_row_len.append(len(i))
self.q_no_list.append(i.q_id)
self.total_time = len(self.q_row_len)
self.total_marks = len(self.q_row_len)
Calling this both methods in _retranlateUi
def retranslateUi(self, Quiz):
self.self.fetchTotalTime_and_TotalMarks()
self.Time()
I want to display time according to total number of questions, continuously updating the label text which is showing time.