Jul-23-2019, 09:02 PM
Hello!
I'm a new coder and am trying to make guizero work for me. My intended program and what works:
- CSV files include the names and student IDs for each student in that class - different CSV per class period/list.
- GUI shows a text entry box for students to enter their IDs. Hit submit button and get a pop-up telling them any of the following:
1. I don't recognize this number (for numbers not in the CSV)
2. You've been marked (absent, tardy, present, or early) for (which hour) hour, (student's name)!
- GUI shows a text widget on the left side with every student name in the class.
- When a student successfully signs in with their ID number, their name disappears from the roster list in that text widget.
- When a student who has signed in has been marked tardy or late enough to be absent, their name still disappears, but reappears in a text widget on the right with their name and tar or abs.
- A clock appears at the bottom showing the current time.
- Every widget is set up to automatically update according to the current time. If it reaches the end of 1st hour, the roster switches to 2nd hour.
All of the above works like a charm. The problem is that when the class period switches over, the tar/abs list doesn't clear. It still lists who was absent or tardy from the previous class. If I log someone else in, their name is added to the list, but the previous class names still remain. No error is given. I have copied my code below:
I'm a new coder and am trying to make guizero work for me. My intended program and what works:
- CSV files include the names and student IDs for each student in that class - different CSV per class period/list.
- GUI shows a text entry box for students to enter their IDs. Hit submit button and get a pop-up telling them any of the following:
1. I don't recognize this number (for numbers not in the CSV)
2. You've been marked (absent, tardy, present, or early) for (which hour) hour, (student's name)!
- GUI shows a text widget on the left side with every student name in the class.
- When a student successfully signs in with their ID number, their name disappears from the roster list in that text widget.
- When a student who has signed in has been marked tardy or late enough to be absent, their name still disappears, but reappears in a text widget on the right with their name and tar or abs.
- A clock appears at the bottom showing the current time.
- Every widget is set up to automatically update according to the current time. If it reaches the end of 1st hour, the roster switches to 2nd hour.
All of the above works like a charm. The problem is that when the class period switches over, the tar/abs list doesn't clear. It still lists who was absent or tardy from the previous class. If I log someone else in, their name is added to the list, but the previous class names still remain. No error is given. I have copied my code below:
from guizero import * import time import pandas as pd stud_dict1 = {str(row[1]): row[0] for _, row in pd.read_csv('1st hour.csv').iterrows()} stud_dict2 = {str(row[1]): row[0] for _, row in pd.read_csv('2nd hour.csv').iterrows()} stud_dict3 = {str(row[1]): row[0] for _, row in pd.read_csv('3rd hour.csv').iterrows()} stud_dict4 = {str(row[1]): row[0] for _, row in pd.read_csv('4th hour.csv').iterrows()} stud_dict5 = {str(row[1]): row[0] for _, row in pd.read_csv('5th hour.csv').iterrows()} stud_dict6 = {str(row[1]): row[0] for _, row in pd.read_csv('6th hour.csv').iterrows()} stud_dict7 = {str(row[1]): row[0] for _, row in pd.read_csv('7th hour.csv').iterrows()} stud_dict8 = {str(row[1]): row[0] for _, row in pd.read_csv('8th hour.csv').iterrows()} stud_dict9 = {str(row[1]): row[0] for _, row in pd.read_csv('9th hour.csv').iterrows()} t = time.localtime() hr = int(time.strftime('%H', t)) mins = int(time.strftime('%M', t)) app = App(title="Attendance") curtime = 'placeholder' what_time = Text(app, text=curtime, align='bottom') roster = stud_dict9 snames = roster.values() snames = '\n'.join(snames) cur_per = 9 names = [] atttitle = 'Yeah, that' hr_title = Text(app, text=atttitle, size=30, align='top') stud_att = {} def update_lists(): global roster global cur_per global stud_dict1 global stud_dict2 global stud_dict3 global stud_dict4 global stud_dict5 global stud_dict6 global stud_dict7 global stud_dict8 global stud_dict9 global stud_att if cur_per == 1 and roster != stud_dict1: roster = stud_dict1 stud_att.clear() elif cur_per == 2 and roster != stud_dict2: roster = stud_dict2 stud_att.clear() elif cur_per == 3 and roster != stud_dict3: roster = stud_dict3 stud_att.clear() elif cur_per == 4 and roster != stud_dict4: roster = stud_dict4 stud_att.clear() elif cur_per == 5 and roster != stud_dict5: roster = stud_dict5 stud_att.clear() elif cur_per == 6 and roster != stud_dict6: roster = stud_dict6 stud_att.clear() elif cur_per == 7 and roster != stud_dict7: roster = stud_dict7 stud_att.clear() elif cur_per == 8 and roster != stud_dict8: roster = stud_dict8 stud_att.clear() elif cur_per == 9 and roster != stud_dict9: roster = stud_dict9 stud_att.clear() def cur_time(): global hr global mins global curtime if int(hr) > 12: curtime_hr = str(int(hr)-12) ampm = "PM" else: curtime_hr = hr ampm = "AM" if int(mins) < 10: curtime_mins = '0'+str(int(mins)) else: curtime_mins = mins curtime = f'{curtime_hr}:{curtime_mins} {ampm}' def auto_refresh(): global hr global mins global t global curtime global what_time global snames global tarabstext global tarabs t = time.localtime() hr = int(time.strftime('%H', t)) mins = int(time.strftime('%M', t)) cur_time() what_time.clear() what_time.append(curtime) hr_title.clear() hr_title.append(atttitle) update_lists() snames = roster.values() snames = '\n'.join(snames) students.clear() students.append(snames) tarabstext.clear() tarabstext.append(tarabs) def current_per(): global cur_per global roster global atttitle if (hr == 8 and mins < 59) or (hr == 9 and mins < 51): cur_per = 1 atttitle = '1st hour' roster = stud_dict1 elif (hr == 9 and mins < 59) or (hr == 10 and mins < 12): cur_per = 2 atttitle = '2nd hour' roster = stud_dict2 elif (hr == 10 and mins < 59) or (hr == 11 and mins < 11): cur_per = 3 atttitle = '3rd hour' roster = stud_dict3 elif (hr == 11 and mins < 59) or (hr == 12 and mins < 5): cur_per = 4 atttitle = '4th hour' roster = stud_dict4 elif hr == 12 and mins < 58: cur_per = 5 atttitle = '5th hour' roster = stud_dict5 elif (hr == 12 and mins < 59) or (hr == 13 and mins < 52): cur_per = 6 atttitle = '6th hour' roster = stud_dict6 elif (hr == 13 and mins < 59) or (hr == 14 and mins < 51): cur_per = 7 atttitle = '7th hour' roster = stud_dict7 elif (hr == 14 and mins < 59) or (hr == 15 and mins < 41): cur_per = 8 atttitle = '8th hour' roster = stud_dict8 else: cur_per = 9 atttitle = 'All Hours' roster = stud_dict9 current_per() enter_id = TextBox(app) submit = PushButton(app, text='Submit ID') att = 'crazy' nth_hr = 'ever' students = Text(app, text=snames, size=12, align='left') tarabs = '\n'. join(stud_att.items()) tarabstext = Text(app, text=tarabs, size=12, align='right') def att_response(): global att global nth_hr if hr == 8: nth_hr = '1st hour' if mins < 30: att = 'early' elif mins < 35: att = 'present' elif mins < 50: att = 'tardy' else: att = 'absent' elif hr == 9: if mins < 24: nth_hr = '1st hour' att = 'absent' elif mins < 29: nth_hr = '2nd hour' att = 'early' elif mins < 34: nth_hr = '2nd hour' att = 'present' elif mins < 49: nth_hr = '2nd hour' att = 'tardy' else: nth_hr = '2nd hour' att = 'absent' elif hr == 16: if mins < 11: nth_hr = '2nd hour' att = 'absent' elif mins < 16: nth_hr = '3rd hour' att = 'early' elif mins < 21: nth_hr = '3rd hour' att = 'present' elif mins < 36: nth_hr = '3rd hour' att = 'tardy' else: nth_hr = '3rd hour' att = 'absent' elif hr == 11: if mins < 10: nth_hr = '3rd hour' att = 'absent' elif mins < 15: nth_hr = '4th hour' att = 'early' elif mins < 20: nth_hr = '4th hour' att = 'present' elif mins < 35: nth_hr = '4th hour' att = 'tardy' else: nth_hr = '4th hour' att = 'absent' elif hr == 12: if mins < 4: nth_hr = '4th hour' att = 'absent' elif mins < 9: nth_hr = '5th hour' att = 'early' elif mins < 14: nth_hr = '5th hour' att = 'present' elif mins < 29: nth_hr = '5th hour' att = 'tardy' elif mins < 58: nth_hr = '5th hour' att = 'absent' else: nth_hr = '6th hour' att = 'early' elif hr == 13: if mins < 3: nth_hr = '6th hour' att = 'early' elif mins < 8: nth_hr = '6th hour' att = 'present' elif mins < 23: nth_hr = '6th hour' att = 'tardy' elif mins < 52: nth_hr = '6th hour' att = 'absent' elif mins < 57: nth_hr = '7th hour' att = 'early' else: nth_hr = '7th hour' att = 'present' elif hr == 14: if mins < 2: nth_hr = '7th hour' att = 'present' elif mins < 17: nth_hr = '7th hour' att = 'tardy' elif mins < 46: nth_hr = '7th hour' att = 'absent' elif mins < 51: nth_hr = '8th hour' att = 'early' elif mins < 56: nth_hr = '8th hour' att = 'present' else: nth_hr = '8th hour' att = 'tardy' elif hr == 15: if mins < 11: nth_hr = '8th hour' att = 'tardy' elif mins < 40: nth_hr = '8th hour' att = 'absent' def take_id(): global stud global snames global students global tarabs global tarabstext global roster if enter_id.value in roster: stud = roster.get(enter_id.value) att_response() info("Yay! You did a thing!", f"You've been marked {att} for {nth_hr}, {stud}!") stud_att[stud] = att del roster[enter_id.value] students.clear() snames = '\n'.join(roster.values()) students.append(snames) enter_id.clear() if stud in stud_att: if stud_att[stud] == 'tardy' or 'absent': tarabstext.clear() tarabs = stud_att.items() tarabs = pd.DataFrame(stud_att.items(), columns=['Name', 'tar/abs']) tarabstext.append(tarabs) else: error("Um....", f"I don't recognize that number {enter_id.value}") auto_refresh() app.repeat(1000, auto_refresh) app.repeat(1000, current_per) submit.when_clicked = take_id print(curtime) app.display()Any help is greatly appreciated.