def main(window): students = [] courses = [] # current_row = 0 # curses.curs_set(0) # curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE) window.title("Student Information System") window.geometry("800x600") if os.path.exists('students.pickle'): file = open('students.pickle', 'rb') students_in_file = pickle.load(file) for student in students_in_file: students.append(student) courses_in_file = pickle.load(file) for course in courses_in_file: courses.append(course) else: file = open('students.pickle', 'wb') # print_menu(stdscr, current_row) thread = BackgroundThread('students.pickle') thread.start() thread.add_objects(students, courses) num_std_btn = tk.Button(window, text="Number of student", command=std_num(window)) num_std_btn.pack() num_course_btn = tk.Button(window, text="Number of student", command=course_num(window)) num_course_btn.pack() add_mark_btn = tk.Button(window, text="Add mark") add_mark_btn.pack() show_student_btn = tk.Button(window, text="Show student list", command=show_students(students, window)) show_student_btn.pack() show_course_btn = tk.Button(window, text="Show course list", command=show_course(courses, window)) show_course_btn.pack() show_gpa_btn = tk.Button(window, text="Show GPA", command=show_gpa(students, window)) show_gpa_btn.pack()
def main(stdscr): students = [] courses = [] current_row = 0 curses.curs_set(0) curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE) if os.path.exists('students.pickle'): with open('students.pickle', 'rb') as file: students_in_file = pickle.load(file) for student in students_in_file: students.append(student) courses_in_file = pickle.load(file) for course in courses_in_file: courses.append(course) else: file = open('students.pickle', 'wb') print_menu(stdscr, current_row) while 1: key = stdscr.getch() stdscr.clear() thread = BackgroundThread('students.pickle', stdscr) thread.start() thread.add_objects(students, courses) if key == curses.KEY_UP and current_row > 0: current_row -= 1 elif key == curses.KEY_DOWN and current_row < len(menu): current_row += 1 elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 0: stdscr.clear() curses.echo() std_number = std_num(stdscr) for i in range(std_number): stdscr.clear() stdscr.addstr(0, 0, f"- Student number {i + 1} info is: ") stdscr.addstr(2, 0, " + Student name: ") student_name = stdscr.getstr(3, 0).decode() stdscr.addstr(4, 0, ' + Student DoB: ') dob = stdscr.getstr(5, 0).decode() students.append(Student(student_name, dob)) stdscr.refresh() with open("student.txt", "w") as sf: for student in students: sf.write( f"{student.get_id()} : {student.get_name()} : {student.get_dob()} \n" ) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 1: stdscr.clear() curses.echo() course_number = course_num(stdscr) for i in range(course_number): stdscr.addstr(0, 0, f"- Course number {i + 1} info is: ") stdscr.addstr(1, 0, f" + Course {i + 1} name: ") course_name = stdscr.getstr(2, 0).decode() stdscr.addstr(3, 0, f" + Course {i + 1} credit: ") course_credit = stdscr.getstr(4, 0).decode() courses.append(Course(course_name, course_credit)) stdscr.refresh() with open("course.txt", "w") as cf: for course in courses: cf.write( f"{course.get_id()}: {course.get_name()} with {course.get_credit()} credit \n" ) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 2: stdscr.clear() curses.echo() stdscr.addstr(0, 0, "- Which course do you want to add marks") course_name = stdscr.getstr(1, 0).decode() course_index = contain_course(course_name, courses) if course_index < 0: stdscr.addstr(2, 0, "This course does not exist") else: courses[course_index].set_mark(students, stdscr) with open("mark.txt", "w") as mf: mf.write(f"{course_name} \n") for name, mark in courses[course_index].get_mark().items(): mf.write(f"{name} : {mark} \n") mf.write("\n") stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 3: stdscr.clear() curses.echo() show_students(students, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 4: stdscr.clear() curses.echo() show_course(courses, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 5: stdscr.clear() curses.echo() show_gpa(students, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 6: thread.join() file.close() break print_menu(stdscr, current_row)
def main(stdscr): students = [] courses = [] current_row = 0 curses.curs_set(0) curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE) print_menu(stdscr, current_row) while 1: key = stdscr.getch() stdscr.clear() if key == curses.KEY_UP and current_row > 0: current_row -= 1 elif key == curses.KEY_DOWN and current_row < len(menu): current_row += 1 elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 0: stdscr.clear() curses.echo() std_number = std_num(stdscr) for i in range(std_number): stdscr.clear() stdscr.addstr(0, 0, f"- Student number {i + 1} info is: ") stdscr.addstr(2, 0, " + Student name: ") student_name = stdscr.getstr(3, 0).decode() stdscr.addstr(4, 0, ' + Student DoB: ') dob = stdscr.getstr(5, 0).decode() students.append(Student(student_name, dob)) stdscr.refresh() stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 1: stdscr.clear() curses.echo() course_number = course_num(stdscr) for i in range(course_number): stdscr.addstr(0, 0, f"- Course number {i + 1} info is: ") stdscr.addstr(1, 0, f" + Course {i + 1} name: ") course_name = stdscr.getstr(2, 0).decode() stdscr.addstr(3, 0, f" + Course {i + 1} credit: ") course_credit = stdscr.getstr(4, 0).decode() courses.append(Course(course_name, course_credit)) stdscr.refresh() stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 2: stdscr.clear() curses.echo() stdscr.addstr(0, 0, "- Which course do you want to add marks") course_name = stdscr.getstr(1, 0).decode() course_index = contain_course(course_name, courses) if course_index < 0: stdscr.addstr(2, 0, "This course does not exist") else: courses[course_index].set_mark(students, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 3: stdscr.clear() curses.echo() show_students(students, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 4: stdscr.clear() curses.echo() show_course(courses, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 5: stdscr.clear() curses.echo() show_gpa(students, stdscr) stdscr.getch() elif (key == curses.KEY_ENTER or key in [10, 17]) and current_row == 6: break print_menu(stdscr, current_row)