Получить данные из одной таблицы в базе данных и отправить их в другую таблицу в базе данных.в питоне ткинтер - PullRequest
0 голосов
/ 22 сентября 2019
class Student:
def __init__(self,root):
    self.root = root
    self.root.title("Student Attandnce system")
    self.root.geometry("1360x700+0+0")
    self.title_frame = Frame(self.root, relief=GROOVE, bd=10, bg="light green")
    self.title_frame.pack(side=TOP, fill=X)
    title = Label(self.title_frame, text="Take Attandence of Student ")
    title.grid(row=0, column=0, sticky="e")
    self.title_frame = Frame(self.root,width=600, height=600 ,relief=GROOVE")
    self.title_frame.pack(side=TOP)

    self.search_by=StringVar()


    Button(self.title_frame,text="Show_Record ",command=self.showallrecords).place(x=100,y=310)
    Button(self.root, text="Submit", command=self.Add_record).place(x=1000, y=410)

def showallrecords(self):
    data = self.readfromdatabase()
    for index, dat in enumerate(data):
        Label(self.title_frame, text=dat[0]).grid(row=index + 1, column=0)
        Label(self.title_frame,text=dat[1]).grid(row=index + 1, column=1)
        Label(self.title_frame ,text=dat[2]).grid(row=index + 1, column=2)
        status = ["Present", "Absent"]
        ttk.Combobox(self.title_frame,textvariable=self.search_by,values=status).grid(row=index + 1, column=3)

def readfromdatabase(self):
    connection = pymysql.connect(host='localhost', user='root', password='', db='sas')
    self.cur = connection.cursor()
    self.cur.execute("SELECT Roll_no,Name,Class FROM studentmanagement")
    return self.cur.fetchall()

def Add_record(self):
    self.showallrecords()
    connection = pymysql.connect(host='localhost', user='root', password='', db='sas')
    cur = connection.cursor()
    data = self.readfromdatabase()
    for dat in data:
        print (dat)# here it show data in console
        cur.execute("INSERT INTO generate_report(Roll_nu,Name,Class,Status)VALUES(%s,%s,%s,%s)(dat))
...