-
Notifications
You must be signed in to change notification settings - Fork 0
/
tkinterDatabase.py
30 lines (23 loc) · 1.07 KB
/
tkinterDatabase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import tkinter as tk
from tkinter import messagebox
import mysql.connector as mysql
def showLastinfo():
db = mysql.connect(host = "hostname", user = "username", passwd = "password")
cursor = db.cursor()
cursor.execute("use databasename")
insrt = "Insert into tablename values('"+fname.get()+"','"+lname.get()+"','"+age.get()+"','"+income.get()+"')"
cursor.execute(insrt)
db.commit()
win = tk.Tk()
win.title("Employee Details")
tk.Label(win, text = "First Name").grid(row = 0)
tk.Label(win, text = "Last Name").grid(row = 1)
tk.Label(win, text = "Age").grid(row = 2)
tk.Label(win, text = "Salary").grid(row = 3)
fname = tk.Entry(win).grid(row = 0, column = 1)
lname = tk.Entry(win).grid(row = 1, column = 1)
age = tk.Entry(win).grid(row = 2, column = 1)
income = tk.Entry(win).grid(row = 3, column = 1)
b1 = tk.Button(win, text = "Quit", command = win.destroy).grid(row = 4, column = 0, pady = 4, sticky = 'W')
b2 = tk.Button(win, text = "Insert", command = showLastinfo).grid(row = 4, column =1 , pady = 4, sticky = 'W')
win.mainloop()