from tkinter import *
from tkinter import ttk
import pymysql

class Database_01:
    def __init__(self,root):
            self.root = root
            self.root.title = ("The Father")
            self.root.geometry ("1350x900+0+0")

            title = Label (self.root, text="The Father", relief=GROOVE, font=("Time New Roman", 40, "bold"), bg="#006643", fg="#FFF")
            title.pack(side = TOP, fill = X)

            #======== Tong_hop_bien =================
            self.UID_var=StringVar()
            self.Password_var=StringVar()
            self.Authenticator_var=StringVar()
            self.Email_var=StringVar()
            self.Phan_loai_var=StringVar()

            #======== Thanh_quan_ly =================
            Thanh_quan_ly = Frame(self.root, bd=4, bg="#E6E6E6", relief=RIDGE)
            Thanh_quan_ly.place(x=50, y=100, width=350)

            a_title = Label(Thanh_quan_ly, text="Quản lý thông tin tài khoản",bg="#E6E6E6", fg="#006643", font=("Times New Roman", 25, "bold"))
            a_title.grid(row=0,columnspan=2,pady=20)

            lb1_uid = Label(Thanh_quan_ly, text="UID", bg="#E6E6E6", fg="#006643", font=("Times New Roman", 14, "bold"))
            lb1_uid.grid(row=1,column=0,pady=10, padx=20, sticky="w")

            txt_UID = Entry(Thanh_quan_ly,textvariable=self.UID_var, font=("Times New Roman", 14, "bold"), bd="1", relief= GROOVE)
            txt_UID.grid(row=1,column=1,pady=10, padx=20, sticky="w")

            lb1_pass = Label(Thanh_quan_ly, text="Password", bg="#E6E6E6", fg="#006643", font=("Times New Roman", 14, "bold"))
            lb1_pass.grid(row=2,column=0,pady=10, padx=20, sticky="w")

            txt_Pass = Entry(Thanh_quan_ly,textvariable=self.Password_var, font=("Times New Roman", 14, "bold"), bd="1", relief= GROOVE)
            txt_Pass.grid(row=2,column=1,pady=10, padx=20, sticky="w")

            lb1_auth = Label(Thanh_quan_ly, text="Authenticator", bg="#E6E6E6", fg="#006643", font=("Times New Roman", 14, "bold"))
            lb1_auth.grid(row=3,column=0,pady=10, padx=20, sticky="w")

            txt_Auth = Entry(Thanh_quan_ly,textvariable=self.Authenticator_var, font=("Times New Roman", 14, "bold"), bd="1", relief= GROOVE)
            txt_Auth.grid(row=3,column=1,pady=10, padx=20, sticky="w")

            lb1_email = Label(Thanh_quan_ly, text="Email", bg="#E6E6E6", fg="#006643", font=("Times New Roman", 14, "bold"))
            lb1_email.grid(row=4,column=0,pady=10, padx=20, sticky="w")

            txt_Email = Entry(Thanh_quan_ly,self.Email_var, font=("Times New Roman", 14, "bold"), bd="1", relief= GROOVE)
            txt_Email.grid(row=4,column=1,pady=10, padx=20, sticky="w")

            lb1_phan_loai = Label(Thanh_quan_ly,textvariable=self.Phan_loai_var, text="Phân loại", bg="#E6E6E6", fg="#006643", font=("Times New Roman", 14, "bold"))
            lb1_phan_loai.grid(row=5,column=0,pady=10, padx=20, sticky="w")

            combo_Phan_loai = ttk.Combobox(Thanh_quan_ly,textvariable=self.Phan_loai_var, font=("Times New Roman", 14), state='readonly')
            combo_Phan_loai['values']=("Via","Clone")
            combo_Phan_loai.grid(row=5,column=1,pady=10, padx=15, sticky="w")

            lb1_note = Label(Thanh_quan_ly, text="Ghi chú", bg="#E6E6E6", fg="#006643", font=("Times New Roman", 14, "bold"))
            lb1_note.grid(row=7,column=0,pady=10, padx=20, sticky="w")

            self.txt_Note = Text(Thanh_quan_ly, width=20, height=4, font=("Times News Roman", 12))
            self.txt_Note.grid(row=7,column=1,pady=10, padx=20, sticky="w")

            #======== Button_Frame =================
            btn_Frame = Frame(self.root, relief=RIDGE)
            btn_Frame.place(x=40, y=550, width=350)

            Addbtn = Button(btn_Frame, text="Tạo mới",command=self.add_database ,relief=GROOVE, font=("Time New Roman", 13, "bold"), bg="#FFF", fg="#006643").grid(row=0, column=0, padx=15)

            Savebtn = Button(btn_Frame, text="Lưu lại", relief=GROOVE, font=("Time New Roman", 13, "bold"), fg="#006643", bg="#000").grid(row=0, column=1, padx=15)

            Clearbtn = Button(btn_Frame, text="Xoá bỏ", relief=GROOVE, font=("Time New Roman", 13, "bold"), fg="#006643", bg="#000").grid(row=0, column=2, padx=15)
            
            Previewbtn = Button(btn_Frame, text="Preview", relief=GROOVE, font=("Time New Roman", 13, "bold"), fg="#006643", bg="#000").grid(row=0, column=3, padx=15)


            #======== du_lieu =================
            du_lieu = Frame(self.root, bd=4, bg="#E6E6E6", relief=RIDGE)
            du_lieu.place(x=500,y=100,width=800,height=700) 

            lb1_search = Label(du_lieu, text="Tìm kiếm theo", bg="#E6E6E6", fg="#006643", font=("Times New Roman", 14, "bold"))
            lb1_search.grid(row=0,column=0,pady=20, padx=20, sticky="w")

            combo_Search = ttk.Combobox(du_lieu, font=("Times New Roman", 14, "bold"), state='readonly')
            combo_Search['values']=("UID","Phân loại","Email","Authenticator")
            combo_Search.grid(row=0,column=1,pady=20, padx=10, sticky="w")
    
            txt_Search = Entry(du_lieu, font=("Times New Roman", 14), bd=2, relief=GROOVE)
            txt_Search.grid(row=0, column=2, pady=10, padx=10, sticky="w")

            searchbtn = Button(du_lieu, text="Tìm kiếm", relief=GROOVE, font=("Time New Roman", 15, "bold"), fg="#006643", bg="#000").grid(row=0,column=3,padx=10,pady=10)

            #======== thong_tin_du_lieu =================
            thong_tin_du_lieu = Frame(du_lieu, bd=4, relief=RIDGE, bg="#E6E6E6")     
            thong_tin_du_lieu.place(x=10,y=70,width=770,height=610)

            Scroll_x = Scrollbar(thong_tin_du_lieu, orient=HORIZONTAL)
            Scroll_y = Scrollbar(thong_tin_du_lieu, orient=VERTICAL)
            acc_du_lieu = ttk.Treeview(thong_tin_du_lieu, columns=("UID","Password","Authenticator","Email","Phân loại","Ghi Chú"),xscrollcommand=Scroll_x.set, yscrollcommand=Scroll_y.set)

            Scroll_x.pack(side=BOTTOM, fill=X)
            Scroll_y.pack(side=RIGHT, fill=Y)
            Scroll_x.config(command=acc_du_lieu.xview)
            Scroll_y.config(command=acc_du_lieu.yview)
            acc_du_lieu.heading("UID",text="UID")
            acc_du_lieu.heading("Password",text="Password")
            acc_du_lieu.heading("Authenticator", text="Authenticator")
            acc_du_lieu.heading("Email", text="Email")
            acc_du_lieu.heading("Phân loại", text="Phân loại")
            acc_du_lieu.heading("Ghi Chú", text="Ghi Chú")
            acc_du_lieu['show']='headings'
            
            acc_du_lieu.column("UID", width=200)
            acc_du_lieu.column("Password",width=200)
            acc_du_lieu.column("Authenticator", width=200)
            acc_du_lieu.column("Email", width=200)
            acc_du_lieu.column("Phân loại", width=100)
            acc_du_lieu.column("Ghi Chú", width=200)
            acc_du_lieu.pack(fill=BOTH,expand=1)

    def add_database(self):
        con = pymysql.Connect(host="", user="root", password="", batabase="")
        cur = con.cursor()
        cur.execute("(%s,%s,%s,%s,%s,%s)",(
                                                            self.UID_var.get(),
                                                            self.Password_var.get(),
                                                            self.Authenticator_var.get(),
                                                            self.Email_var.get(),
                                                            self.Phan_loai_var.get(),
                                                            self.txt_Note.get(1.0, END),
            ))
        con.commit()
        con.close() 


root = Tk()
ob = Database_01(root)
root.mainloop()