Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books