You are on page 1of 2

import tkinter as tk

from tkinter import messagebox

class SinhVien:
def __init__(self, ma_sv, ho_ten, gioi_tinh, ngay_sinh, lop):
self.ma_sv = ma_sv
self.ho_ten = ho_ten
self.gioi_tinh = gioi_tinh
self.ngay_sinh = ngay_sinh
self.lop = lop

class QuanLySinhVienGUI:
def __init__(self):
self.window = tk.Tk()
self.window.title("Quản Lý Sinh Viên")
self.window.geometry("1250x700+150+50")
self.create_gui()

self.sinh_vien_list = []

def create_gui(self):
# Tạo các đối tượng GUI
self.lbl_ma_sv = tk.Label(self.window, text="Mã SV:")
self.lbl_ma_sv.grid(row=17, column=30, padx=5, pady=5)
self.txt_ma_sv = tk.Entry(self.window)
self.txt_ma_sv.grid(row=17, column=31, padx=5, pady=5)

self.lbl_ho_ten = tk.Label(self.window, text="Họ Tên:")


self.lbl_ho_ten.grid(row=18, column=30, padx=5, pady=5)
self.txt_ho_ten = tk.Entry(self.window)
self.txt_ho_ten.grid(row=18, column=31, padx=5, pady=5)

self.lbl_gioi_tinh = tk.Label(self.window, text="Giới Tính:")


self.lbl_gioi_tinh.grid(row=19, column=30, padx=5, pady=5)
self.txt_gioi_tinh = tk.Entry(self.window)
self.txt_gioi_tinh.grid(row=19, column=31, padx=5, pady=5)

self.lbl_ngay_sinh = tk.Label(self.window, text="Ngày Sinh:")


self.lbl_ngay_sinh.grid(row=20, column=30, padx=5, pady=5)
self.txt_ngay_sinh = tk.Entry(self.window)
self.txt_ngay_sinh.grid(row=20, column=31, padx=5, pady=5)

self.lbl_lop = tk.Label(self.window, text="Lớp:")


self.lbl_lop.grid(row=21, column=30, padx=5, pady=5)
self.txt_lop = tk.Entry(self.window)
self.txt_lop.grid(row=21, column=31, padx=5, pady=5)

def them_sinh_vien(self):
# Lấy thông tin sinh viên từ các ô nhập liệu
ma_sv = self.txt_ma_sv.get()
ho_ten = self.txt_ho_ten.get()
gioi_tinh = self.txt_gioi_tinh.get()
ngay_sinh = self.txt_ngay_sinh.get()
lop = self.txt_lop.get()

# Kiểm tra thông tin đã nhập đủ chưa


if ma_sv == "" or ho_ten == "" or gioi_tinh == "" or ngay_sinh == "" or lop
== "":
messagebox.showerror("Lỗi", "Vui lòng nhập đầy đủ thông tin sinh
viên.")
else:
# Tạo đối tượng sinh viên mới
sinh_vien = SinhVien(ma_sv, ho_ten, gioi_tinh, ngay_sinh, lop)
# Thêm sinh viên vào danh sách
self.sinh_vien_list.append(sinh_vien)
# Cập nhật giao diện
self.lbl_ket_qua.config(text="Thêm sinh viên thành công.")
# Xóa dữ liệu trên các ô nhập liệu
self.clear_input()

def xem_sinh_vien(self):
# Hiển thị danh sách sinh viên trong MessageBox
if self.sinh_vien_list:

You might also like