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()

tab widget python tkinter

     



import tkinter as tk  

from tkinter import ttk 



root = tk.Tk() 

root.title("Tab Widget") 

tabControl = ttk.Notebook(root) 


tab1 = ttk.Frame(tabControl) 

tab2 = ttk.Frame(tabControl) 

tab3 = ttk.Frame(tabControl) 


tabControl.add(tab1, text ='Tab 1') 

tabControl.add(tab2, text ='Tab 2') 

tabControl.add(tab3, text ='Tab 3') 

tabControl.pack() 


ttk.Label(tab1,text ="evening class").grid(column = 0, 

row = 0, 

padx = 30, 

pady = 62) 

ttk.Label(tab2, 

text ="praveen is thopu").grid(column = 0, 

row = 0, 

padx = 30, 

pady = 100) 

                                 

ttk.Label(tab3, 

text ="chiranjivi is thopu").grid(column = 0, 

row = 0, 

padx = 30, 

pady = 100) 


root.mainloop() 


python class topic video