I am new to Python I have recently start to learn 1 week ago and I am stuck here... Any help will be appreciate...
from tkinter import *
import tkinter as tk
import psycopg2
root = Tk()
def get_info(Employee_Name, Department, Education,Salary):
con = psycopg2.connect(dbname = 'postgres',user = 'postgres',password = 'Gaurav@31',host = 'localhost',port = 5432)
cur = con.cursor()
query = ('''INSERT INTO Employee (Employee_name, Department, Education,Salary) VALUES (%s,%s,%s,%s);''' )
cur.execute(query,(Employee_Name, Department, Education,Salary))
print('Data inserted Successfully')
con.commit()
con.close()
display_all()
def search(emp_id):
con = psycopg2.connect(dbname = 'postgres',user = 'postgres',password = 'Gaurav@31',host = 'localhost',port = 5432)
cur = con.cursor()
query = ('''SELECT * FROM EMPLOYEE WHERE emp_id = %s;''' )
cur.execute(query,(emp_id))
row = cur.fetchone()
display_search(row)
con.commit()
con.close()
def display_search(row):
listbox = Listbox(frame, width =50 , height=1)
listbox.grid(row = 9 , column =1)
listbox.insert(END,row)
def display_all():
con = psycopg2.connect(dbname = 'postgres',user = 'postgres',password = 'Gaurav@31',host = 'localhost',port = 5432)
cur = con.cursor()
query = ('''SELECT * FROM Employee;''' )
cur.execute(query)
row = cur.fetchall()
listbox = Listbox(frame, width =50 , height=8)
listbox.grid(row = 10 , column =1)
for x in row:
listbox.insert(END,x)
canvas = Canvas(root, height = 480, width = 900)
canvas.pack()
frame = Frame()
frame.config(background="Black")
frame.place(relx = 0, rely = 0, relwidth = 1, relheight = 1)
label = Label(frame,text = " Employee Database")
labelfont = ('times', 24, 'bold')
label.config(bg = 'Black',fg ='Yellow',font =labelfont)
label.grid(row=0,column=1,sticky = N)
label = Label(frame, text = 'Employee Name : ')
labelfont1 = ('times', 18, 'bold')
label.config(bg = 'Black',fg ='Yellow',font =labelfont1)
label.grid(row =1, column = 0,sticky='w')
entry_name = Entry(frame,width = 30)
entry_name.grid(row = 1, column= 1)
label = Label(frame, text = 'Department : ')
labelfont1 = ('times', 18, 'bold')
label.config(bg = 'Black',fg ='Yellow',font =labelfont1)
label.grid(row =2, column = 0, sticky ='w')
dept_name = Entry(frame,width = 30)
dept_name.grid(row = 2, column= 1)
label = Label(frame, text = 'Education : ')
labelfont1 = ('times', 18, 'bold')
label.config(bg = 'Black',fg ='Yellow',font =labelfont1)
label.grid(row =3, column = 0,sticky ='w')
education = Entry(frame,width = 30)
education.grid(row = 3, column= 1)
label = Label(frame, text = 'Salary : ')
labelfont1 = ('times', 18, 'bold')
label.config(bg = 'Black',fg ='Yellow',font =labelfont1)
label.grid(row =4, column = 0, sticky ='w')
salary = Entry(frame,width = 30)
salary.grid(row = 4, column= 1)
button = Button(frame, text = 'Add Information', command=lambda: get_info(entry_name.get(),dept_name.get(),education.get(),salary.get()))
buttonfont1 = ('times', 13, 'bold')
button.config(bg = 'Black',fg ='Yellow',font =buttonfont1)
button.grid(row = 5 , column= 1)
label = Label(frame, text = 'Search by Emp_id : ')
labelfont1 = ('times', 14, 'bold')
label.config(bg = 'Black',fg ='Yellow', font =labelfont1)
label.grid(row = 6, column = 0, sticky ='w')
id_search = Entry(frame,width = 30)
id_search.grid(row = 6, column= 1)
button = Button(frame, text = 'Search',command = lambda: search(id_search.get()))
buttonfont1 = ('times', 13, 'bold')
button.config(bg = 'Black',fg ='Yellow',font =buttonfont1)
button.grid(row = 7 , column= 1)
display_all()
root.mainloop()
Please find the attached code as well as Screenshot :
I will to remove the curly bracket which is visible on in the listbox, As well as I wish to print this in a tabular form
See Question&Answers more detail:
os