Tuesday, February 9, 2021

python day 34 tkinter with mysql connection


from tkinter import*

import pymysql



def create_table():

    conn=pymysql.connect(host="localhost",user="root",password="",db="sslabs")

    mycursor=conn.cursor()

    mycursor.execute("CREATE TABLE hotel (id INT AUTO_INCREMENT PRIMARY KEY, dosa VARCHAR(255),idle VARCHAR(255))")

    sql = "INSERT INTO hotel (dosa, idle) VALUES (%s, %s)"

   

    #sub=e3.get()

    #val = (dosa1, idle1)

    #mycursor.execute(sql, val)

    conn.commit()

    print(mycursor.rowcount, "record inserted.")


def show_entry_fields():

    #create_table()

    conn=pymysql.connect(host="localhost",user="root",password="",db="sslabs")

    mycursor=conn.cursor()

    #print("First Name: %s\nstandard:%s\nsubject:%s" % (e1.get(),e2.get(),e3.get()))

    #query = "SELECT * FROM student"

    ## getting records from the table

    #mycursor.execute(query)

    ## fetching all records from the 'cursor' object

    #records = mycursor.fetchall()

    ## Showing the data

    #for record in records:

        #print(record)

    a=e1.get()

    print(a)

    b=e2.get()

    print(b)

    sql = "INSERT INTO hotel (dosa, idle) VALUES (%s, %s)"

   

    #sub=e3.get()

    val = (a, b)

    mycursor.execute(sql, val)

    

    conn.commit()

    

    


praveen=Tk()

praveen.geometry("500x300")

praveen.title("Hotel management")



Label(praveen, text="dosa").grid(row=0)

Label(praveen , text="idle").grid(row=1)



e1=Entry(praveen)

name=e1.grid(row=0,column=1)



e2=Entry(praveen)

standard = e2.grid(row=1,column=1)



Button(praveen,text='Quit', command=praveen.quit).grid(row=2,column=0,sticky=W,pady=4)

Button(praveen,text='Show', command=show_entry_fields).grid(row=2,column=1,sticky=W,pady=4)

#Button(praveen,text='Insert', command=create_table).grid(row=2,column=2,sticky=W,pady=4)



mainloop()

No comments:

Post a Comment

python class topic video