I am trying to get the data from fields but it is not returning anything. Please help in obtaining the data in the variables so that the same can be inserted in the MySQL. I am trying to get the data from fields but it is not returning anything. Please help in obtaining the data in the variables so that the same can be inserted in the MySQL.
from tkinter import *
from tkinter import messagebox
import pymysql
import mysql.connector
def front():
root1 = Toplevel()
root1.title("PAYROLL MANAGEMENT")
root1.geometry("500x200+500+260")
label5 = Label(root1, text="PAYROLL MANAGEMENT SYSTEM", font=("Georgia", 19,"bold"), fg="mediumblue")
label5.place(x=17, y=0)
print1="Enter the name of the database: "
msg4 = Message(root1, text=print1, font=('Georgia', 14), width=885, fg="black")
msg4.place(x=10, y=60)
Entry22 = Entry(root1,bg="lightyellow")
Entry22.place(x=350, y=73)
print1 = "Enter the name of the table: "
msg40 = Message(root1, text=print1, font=('Georgia', 14), width=885, fg="black")
msg40.place(x=10, y=90)
Entry22_ = Entry(root1,bg="lightyellow")
Entry22_.place(x=350, y=105)
def data1():
global a
a=Entry22.get()
global b
b = Entry22_.get()
print(b)
mydatabase = mysql.connector.connect(host="localhost", user="root", passwd="mysql@123")
mycursor = mydatabase.cursor()
mycursor.execute("CREATE DATABASE if not exists %s" %a)
print("Database created Succesfully....")
mycursor = mydatabase.cursor()
mycursor.execute("Use " + a)
query = "Create table if not exists " + b + " \
(Employee_Code varchar(20) not null primary key,\
Department varchar(30),\
Designation varchar(30),\
Dob varchar(30),\
Address varchar(50),\
Month varchar(20),\
Year varchar(20),\
Email varchar(40),\
Doj varchar(30),\
Gender varchar(30),\
Employee_Name varchar(40) not null,\
Aadhaar_No varchar(12),\
Absents varchar(10),\
PF_No varchar(10),\
Age varchar(10),\
Total_Days varchar(10),\
Basic_Salary varchar(10),\
Contact_No varchar(10),\
Medical varchar(10),\
Convince varchar(10),\
Provident_Fund varchar(10),\
Net_Salary varchar(10))"
print("Table " + b + " created succesfully....")
mycursor.execute(query)
payroll()
myButton = Button(root1, text="Enter",command=data1)
myButton.place(x=220, y=150)
root1.mainloop()
def payroll():
class EmployeeSystem:
def __init__(self, root):
self.root = root
self.root.title("Employee Payroll Management System")
self.root.geometry("1365x740+80+20")
self.root.config(bg="white")
title = Label(self.root, text="Payroll Management System", font=("times new roman", 30, "bold"), bg="blue",
fg="white", anchor="w", padx=10).place(x=0, y=0, relwidth=1)
# ============================Frame1====================
self.var_empcode = StringVar()
self.var_designation = StringVar()
Frame1 = Frame(self.root, bd=5, relief=RIDGE, bg="white")
Frame1.place(x=10, y=70, width=750, height=650)
title1 = Label(Frame1, text="Employee Details", font=("times new roman", 20), bg="lightgray", fg="black",anchor="w", padx=10).place(x=0, y=0, relwidth=1)
lbl_code = Label(Frame1, text="Employee code", font=("times new roman", 20), bg="white", fg="black").place(x=10, y=70)
# txt_code = Entry(Frame1, font=("times new roman", 15), textvariable = self.var_empcode, bg="lightyellow",fg="black").place(x=220, y=75, width=200)
a = Entry(Frame1, font=("times new roman", 15), bg="lightyellow",fg="black").place(x=220, y=75, width=200)
but_serach = Button(Frame1, text="Search", font=("times new roman", 20), bg="gray", fg="black").place(x=470,y=74,height=30)
# ===============row1
lbl_designation = Label(Frame1, text="Designation", font=("times new roman", 20), bg="white",fg="black").place(x=10, y=120)
txt_designation = Entry(Frame1, font=("times new roman", 15), textvariable=self.var_designation,bg="lightyellow", fg="black").place(x=170, y=125, width=170)
lbl_doj = Label(Frame1, text="Date of join", font=("times new roman", 20), bg="white", fg="black").place(x=380, y=120)
txt_doj = Entry(Frame1, font=("times new roman", 15), textvariable=self.var_DOJ, bg="lightyellow",fg="black").place(x=520, y=125)
but_calculate = Button(Frame2, text="Calculate", font=("times new roman", 20),bg="gray", fg="black").place(x=160, y=250, height=30, width=120)
but_save = Button(Frame2, text="Save", font=("times new roman", 20),command=self.add, bg="gray", fg="black").place(x=300,y=250,height=30,width=120)
but_clear = Button(Frame2, text="Clear", font=("times new roman", 20), bg="gray", fg="black").place(x=440,y=250,height=30,width=120)
# ===================================================== FUNCTIONS ==========================
def add(self):
mydatabase = mysql.connector.connect(host="localhost", user="root", passwd="mysql@123")
mycursor = mydatabase.cursor()
mycursor.execute("Use " + a)
tup = (self.var_empcode.get(),
self.var_Department.get())
sql = "insert into " + b + " values(%s,%s)"
print(sql,tup)
mycursor.execute(sql,tup)
mydatabase.commit()
mydatabase.close()
messagebox.showinfo("Success", "Record added Successfully.", parent=self.root)
root = Tk()
obj = EmployeeSystem(root)
root.mainloop()
root=Tk()
root.geometry("250x100+600+300")
label1=Label (root, text="Username", font=("Georgia", 9,"bold"))
label1.place(x=15,y=10)
label1=Label (root, text="Password", font=("Georgia", 9,"bold"))
label1.place(x=15,y=35)
Entry1=Entry(root)
Entry1.place(x=100,y=10)
Entry2=Entry(root)
Entry2.place(x=100,y=35)
def login():
s=Entry1.get()
s1=Entry2.get()
print(s,s1)
if s=="" and s1=="":
front()
else:
messagebox.showerror("ERROR", "Wrong Username or Password.")
Button1=Button(root,text="Login",bg="lime",command=login)
Button1.place(x=105,y=70)
root.mainloop()