Question: here is my python GUI code for a Tutors help desk, it allow to add and remove students from a queue. I would like to
here is my python GUI code for a Tutors help desk, it allow to add and remove students from a queue. I would like to be able to calculate the average wait time of the students between being added to the queue and being removed( receiving help) this average time should be display at the top right and being updated along the adding and removing of students, the clock is already present for the EST time in the GUI:
import sys
import time
from PyQt5.QtWidgets import (QApplication, QWidget, QPushButton, QHBoxLayout,
QVBoxLayout, QLineEdit, QLabel, QListWidget, QLCDNumber)
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("CS2316 Help Desk Queue")
self.initUI()
self.timer = QTimer()
self.timer.timeout.connect(self.showlcd)
self.timer.start(1000)
self.showlcd()
def initUI(self):
self.lcd = QLCDNumber(self)
self.setGeometry(30, 30, 600, 600)
palette = self.lcd.palette()
palette.setColor(palette.Dark, QColor("black"))
self.lcd.setPalette(palette)
self.lcd.setSegmentStyle(QLCDNumber.Flat)
vbox = QVBoxLayout()
hbox1 = QHBoxLayout()
label = QLabel()
label.setText("TAs on Duty:")
hbox1.addWidget(label)
Ta_entry = QLineEdit()
hbox1.addWidget(Ta_entry)
hbox2 = QHBoxLayout()
label2 = QLabel()
label2.setText("Enter Your Name:")
hbox2.addWidget(label2)
self.students_entry = QLineEdit()
self.students_entry.textChanged.connect(self.s_lineEdit)
hbox2.addWidget(self.students_entry)
self.b1 = QPushButton("Add")
self.b1.clicked.connect(self.on_b1_clicked)
self.b1.setEnabled(False)
self.b1.setStyleSheet('QPushButton {background-color: light grey; color: green;}')
self.b2 = QPushButton("Remove")
self.b2.clicked.connect(self.on_b2_clicked)
self.b2.setEnabled(False)
self.b2.setStyleSheet('QPushButton {background-color: light grey; color: red;}')
self.student_list = QListWidget()
self.student_list.itemSelectionChanged.connect(self.s_select)
vbox.addWidget(self.lcd)
vbox.addLayout(hbox1)
vbox.addWidget(self.student_list)
vbox.addLayout(hbox2)
vbox.addWidget(self.b1)
vbox.addWidget(self.b2)
self.setLayout(vbox)
def on_b1_clicked(self):
self.student_list.addItem(self.students_entry.text())
self.b1.setEnabled(False)
self.students_entry.clear()
def on_b2_clicked(self):
listItems = self.student_list.selectedItems()
for item in listItems:
self.student_list.takeItem(self.student_list.row(item))
def s_lineEdit(self):
if len(self.students_entry.text()) > 0 :
self.b1.setEnabled(True)
else:
self.b1.setEnabled(False)
def s_select(self):
if self.student_list.selectedItems():
self.b2.setEnabled(True)
else:
self.b2.setEnabled(False)
def showlcd(self):
time = QTime.currentTime()
text = time.toString('hh:mm')
self.lcd.display(text)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())
#display average wait time in the queue
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
