Sunday, January 31, 2021

python day 29 tkinter class1

 # -*- coding: utf-8 -*-

"""

Created on Mon Feb  1 07:09:50 2021


@author: anil



import tkinter


window=tkinter.Tk()

window.geometry("1024x768")

window.mainloop()




import tkinter


window=tkinter.Tk()

window.geometry("1920x1080")

window.mainloop()


import tkinter

#from tkinter import *


window=tkinter.Tk()

window.geometry("1920x1080")

Button(window,text='Quit', command=master.quit)

window.mainloop()

"""



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 student2 (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255),standard VARCHAR(255), sub VARCHAR(255) )")

    sql = "INSERT INTO student2 (name, standard,sub) VALUES (%s, %s,%s)"

 

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

    name=e1.get()

    standard=e2.get()

    sub=e3.get()

    val = (name, standard, sub)

    mycursor.execute(sql, val)

    conn.commit()

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


def show_entry_fields():

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

    query = "SELECT * FROM student2"

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


master=Tk()

master.geometry("500x300")

master.title("Hotel management")



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

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

Label(master , text="puri").grid(row=2)

Label(master , text="wada").grid(row=3)

Label(master , text="Bonda").grid(row=4)

Label(master , text="Upma").grid(row=5)


e1=Entry(master)

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

e2=Entry(master)

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

e3=Entry(master)

sub = e3.grid(row=2,column=1)


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

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

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



mainloop()






No comments:

Post a Comment

python class topic video