Sep-13-2021, 06:57 AM
Hi all,
I have made a form in Tkinter to make entries in MySql database. I would like the Sr. No. entry box to display the next available number. i.e if i have 5 entries at 1,2,3,4,5 and I have to add another the sr.no. entry box should automatically show No.6. My present code is
I have made a form in Tkinter to make entries in MySql database. I would like the Sr. No. entry box to display the next available number. i.e if i have 5 entries at 1,2,3,4,5 and I have to add another the sr.no. entry box should automatically show No.6. My present code is
import tkinter as tk from tkinter import* import mysql.connector mydb= mysql.connector.connect(host="localhost",user="root", password="mudit",database="Clinicmaster",auth_plugin="mysql_native_password") cursor=mydb.cursor() def addwork(): srno=ent3.get() work=ent4.get() sql=("INSERT INTO workrequired(srno,work)" "VALUES(%s,%s)" ) cursor.execute(sql,(srno,work)) mydb.commit() print("DONE") return True win=Tk() win.title("ADD Work") win.geometry("300x250") win.configure(background='light blue') win.resizable(False,False) frm1=Frame(win,bg="light blue") frm1.pack(side=tk.LEFT,padx=20) var3=StringVar() srno=StringVar() var4=StringVar() workrequired=StringVar() label3=Label(frm1,textvariable=var3,bg="light blue") var3.set("Sr.No.") label3.grid(row=2,column=1,padx=10,pady=10) ent3=Entry(frm1,textvariable=srno,width=10) srno.set(" ") ent3.grid(row=2,column=2,sticky=tk.W,padx=10,pady=10) label4=Label(frm1,textvariable=var4,bg="light blue") var4.set("Work Required") label4.grid(row=3,column=1,padx=10,pady=10) ent4=Entry(frm1,textvariable=workrequired) workrequired.set(" ") ent4.grid(row=3,column=2,padx=10,pady=10) btn=Button(frm1, text="ADD",command=addwork) btn.grid(row=5,column=2,padx=10,pady=10) win.mainloop()