import sqlite3
from tkinter import messagebox
from tkinter import *
from tkinter import ttk
from tkinter.ttk import *
class connect_db:
def__init__(self, db_name):
self.db_name = db_name
self.connector = sqlite3.connect(self,db_name)
self.cursor = self.connector.cursor()
def execute_sql(self,sql_txt):
try:
self.sql_txt = sql_txt
return self.cursor.execute(self.sql_txt)
except:
messagebox.showerror("Ошибка!","Невозможно получить данные!")
def close_db(self):
self.connector.commit()
self.cursor.close()
self.connector.close()
class my_window:
def __init__(self):
self.window = Tk()
self.window.geometry = ("1980x1040")
self.window.title(" Сессия 1 & 2 курс")
self.create_frames()
self.window.mainloop()
def update_tables(self, table):
self.new_connect = connect_db ("ssessionn.db")
if table == self.table_perv:
self.sql = self.new_connect.execute_sql(f"SELECT * from uspevone")
for row in self.sql:
self.db_fio = row[1]
self.db_russ = row[2]
self.table_perv.insert ("", END, values=[self.db_fio, self.db_russ])
self.new_connect.close_db()
def create_frames(self):
self.notebook = ttk.Notebook()
style = Style()
style.configure ("TFrame", background = "lightblue")
self.notebook.pack(expand=True, fill=BOTH)
self.frame1 = Frame(self.notebook)
self.frame2 = Frame (self.notebook)
self.frame1.pack(fill=BOTH, expand=True)
self.frame2.pack(fill=BOTH, expand=True)
self.notebook.add(self.frame1, text="1й курс")
self.notebook.add(self.frame2, text="2й курс")
self.frame_perv()
self.frame_vtor()
def frame_perv(self):
self.table_perv = Treeview(self.frame1, columns=["fio", "russ", "matem","inform","fizika","himi","biol","astro"], show="headings")
self.table_perv.heading("fio", text="ФИО")
self.table_perv.heading("russ", text="Русский")
self.table_perv.heading("matem",text= "Математика")
self.table_perv.heading("inform",text= "Информатика")
self.table_perv.heading("fizika",text= "Физика")
self.table_perv.heading("himi",text= "Химия")
self.table_perv.heading("biol",text= "Биология")
self.table_perv.heading("astro",text= "Астрономия")
self.table_perv.column("fio", width=40, anchor="c")
self.table_perv.column("russ", width=40, anchor="c")
self.table_perv.column("matem", width=40, anchor="c")
self.table_perv.column("inform", width=40, anchor="c")
self.table_perv.column("fizika", width=40, anchor="c")
self.table_perv.column("himi", width=40, anchor="c")
self.table_perv.column("biol", width=40, anchor="c")
self.table_perv.column("astro", width=40, anchor="c")
self.table_perv.place(x=1,y=10)
self.fio_add = StringVar()
self.lb_name = Label(self.frame1, text="Введите ФИО студента", font="Arial 12", background="red")
self.lb_name.place(x=1, y=300)
self.entry_name = Entry(self.frame1, textvariable=self.fio_add, font="Arial 12" )
self.entry_name.place(x=1, y=330)
self.ocen_add = StringVar()
self.lb_name = Label(self.frame1, text="Введите результат экзамена", font="Arial 12", background="red")
self.lb_name.place(x=360, y=300)
self.entry_name = Entry(self.frame1, textvariable=self.fio_add, font="Arial 12")
self.entry_name.place(x=360, y=330)
#кнопки
self.btn_new_stud = Button(self.frame1, text="Добавить студента и его результаты")
self.btn_new_stud.place(x=600, y=300)
self.btn_del_stud = Button(self.frame1, text="Удалить данные и результаты студента")
self.btn_del_stud.place(x=820, y=300)
self.btn_upd_st
self.btn_upd_stud = Button(self.frame1, text="Изменить данные и результаты студента")
self.btn_upd_stud.place(x=1070, y=300)
self.update_tables(self.table_perv)
self.table_perv.bind("<<TreeviewSelect>>", lambda event:
self.select_uspevone(self.uspevone_fio, self.uspevone_russ))
def select_uspevone(self,uspevone_fio, uspevone_russ):
for row in self.table_perv.selection():
uspevone_fio.set(self.table_perv.item(row)["values"][0])
uspevone_russ.set(self.table_perv.item(row)["values"][1])