Загрузил yura

python

реклама
# import tkinter as tk
# from tkinter import messagebox
#
#
# class Student:
# def __init__(self, name, group, grades):
# self.name = name
# self.group = group
# self.grades = grades
#
#
# def add_student(students):
# name = name_entry.get()
# group = int(group_entry.get())
# grades = [int(x) for x in grades_entry.get().split(",")]
# student = Student(name, group, grades)
# students.append(student)
# messagebox.showinfo("Успех", "Студент добавлен")
#
#
# def read_data(students):
# filename = filename_entry.get()
# try:
# with open(filename, "r") as f:
# for line in f:
# data = line.strip().split(",")
# name = data[0]
# group = int(data[1])
# grades = [int(x) for x in data[2:]]
# student = Student(name, group, grades)
# students.append(student)
# messagebox.showinfo("Успех", "Данные успешно считаны из файла.")
# except FileNotFoundError:
# messagebox.showerror("Ошибка", "Указанный файл не найден.")
# except Exception as e:
# messagebox.showerror(
# "Ошибка", f"Произошла ошибка при чтении файла: {e}")
#
#
# def write_data(students):
# filename = filename_entry.get()
# try:
# with open(filename, "w") as f:
# for student in students:
# f.write(
# f"{student.name},{student.group},{','.join(map(str, student.grades))}\n")
# messagebox.showinfo("Успех", "Данные успешно записаны в файл.")
# except Exception as e:
# messagebox.showerror(
# "Ошибка", f"Произошла ошибка при записи в файл: {e}")
#
#
# def sort_data(students):
# choice = sort_choice.get()
# if choice == "1":
# students.sort(key=lambda x: x.name)
# elif choice == "2":
# students.sort(key=lambda x: x.group)
# elif choice == "3":
# students.sort(key=lambda x: sum(x.grades) /
# len(x.grades), reverse=True)
# else:
# messagebox.showerror("Ошибка", "Неверный выбор. Попробуйте снова.")
# return
# messagebox.showinfo("Успех", "Данные успешно отсортированы")
#
#
# def search_data(students):
# choice = search_choice.get()
# value = search_value.get()
# if choice == "1":
# result = [student for student in students if student.name == value]
# elif choice == "2":
# result = [
# student for student in students if student.group == int(value)]
# else:
# messagebox.showerror("Ошибка", "Неверный выбор. Попробуйте снова.")
# return
# messagebox.showinfo("Результат", f"Найдено {len(result)} записей:\n" + "\n".join(
# [f"{student.name} ({student.group})" for student in result]))
#
#
# def filter_data(students):
# choice = filter_choice.get()
# value = filter_value.get()
# if choice == "1":
# result = [student for student in students
# if any([grade >= int(value) for grade in student.grades])]
# elif choice == "2":
# result = [student for student in students
# if all([grade >= int(value) for grade in student.grades])]
# else:
# messagebox.showerror("Ошибка", "Неверный выбор. Попробуйте снова.")
# return
# if not result:
# messagebox.showinfo(
# "Результат", "Нет записей, удовлетворяющих условию.")
# else:
# messagebox.showinfo("Результат", f"Найдено {len(result)} записей:\n" + "\n".join(
# [f"{student.name} ({student.group}): {','.join(map(str, student.grades))}" for student in result]))
#
#
# def clear_data(students):
# answer = messagebox.askyesno(
# "Подтверждение", "Вы уверены, что хотите очистить данные?")
# if answer:
# students.clear()
# messagebox.showinfo("Успех", "Данные очищены.")
# else:
# messagebox.showinfo("Отмена", "Очистка данных отменена.")
#
#
# root = tk.Tk()
# root.title("Учет студентов")
# root.geometry("600x400")
#
# # Name label and entry
# name_label = tk.Label(root, text="Имя:")
# name_label.grid(row=0, column=0, padx=5, pady=5)
# name_entry = tk.Entry(root)
# name_entry.grid(row=0, column=1, padx=5, pady=5)
#
# # Group label and entry
# group_label = tk.Label(root, text="Группа:")
# group_label.grid(row=1, column=0, padx=5, pady=5)
# group_entry = tk.Entry(root)
# group_entry.grid(row=1, column=1, padx=5, pady=5)
#
# # Grades label and entry
# grades_label = tk.Label(root, text="Оценки (через запятую):")
# grades_label.grid(row=2, column=0, padx=5, pady=5)
# grades_entry = tk.Entry(root)
# grades_entry.grid(row=2, column=1, padx=5, pady=5)
#
# # Filename label and entry
# filename_label = tk.Label(root, text="Имя файла:")
# filename_label.grid(row=3, column=0, padx=5, pady=5)
# filename_entry = tk.Entry(root)
# filename_entry.grid(row=3, column=1, padx=5, pady=5)
#
# # Search label and radio buttons
# search_label = tk.Label(root, text="Искать по:", font=("Arial", 12))
# search_label.grid(row=7, column=1, pady=10)
# search_choice = tk.StringVar(value="1")
# tk.Radiobutton(root, text="Имени", variable=search_choice,
# value="1").grid(row=8, column=1)
# tk.Radiobutton(root, text="Группе", variable=search_choice,
# value="2").grid(row=9, column=1)
# search_value = tk.Entry(root)
# search_value.grid(row=10, column=1)
#
# # Filter label and radio buttons
# filter_label = tk.Label(root, text="Фильтровать по:", font=("Arial", 12))
# filter_label.grid(row=7, column=2, pady=10)
# filter_choice = tk.StringVar(value="1")
# tk.Radiobutton(root, text="Оценке выше или равной",
# variable=filter_choice, value="1").grid(row=8, column=2)
# tk.Radiobutton(root, text="Оценке выше всех",
# variable=filter_choice, value="2").grid(row=9, column=2)
# filter_value = tk.Entry(root)
# filter_value.grid(row=10, column=2)
#
# # Students table
# students_table = tk.Frame(root)
# students_table.grid(row=11, column=0, columnspan=3, pady=20)
# table_columns = ["Имя", "Группа", "Оценки"]
# for i in range(len(table_columns)):
# tk.Label(students_table, text=table_columns[i], font=(
# "Arial", 12)).grid(row=0, column=i)
#
#
# def update_table(students):
# for i in range(len(students)):
# student = students[i]
# tk.Label(students_table, text=student.name).grid(row=i + 1, column=0)
# tk.Label(students_table, text=student.group).grid(row=i + 1, column=1)
# tk.Label(students_table, text=", ".join(
# [str(x) for x in student.grades])).grid(row=i + 1, column=2)
#
#
# # Clear button
# tk.Button(root, text="Очистить", command=lambda: clear_table(
# students_table)).grid(row=12, column=1)
#
# # Update table button
# tk.Button(root, text="Обновить таблицу",
# command=lambda: update_table(students)).grid(row=12, column=2)
#
# root.mainloop()
Скачать