You are on page 1of 6

from tkinter import *

from tkinter import messagebox


import mysql.connector
import random
conn=mysql.connector.connect(host='localhost',
user='root',
password=''
)
mycur=conn.cursor()
uid=''
def data_base():
mycur.execute('create database if not exists bank')
mycur.execute('use bank')
mycur.execute('create table if not exists customer (userid varchar(20) primary
key,password varchar(20) not null,name varchar(20) not null,acctno
varchar(10),contactno varchar(10),address varchar(50),balance float(8,2),tranno
int,transto int,transdate date)')
data_base()
def register():
root4 =Tk()
root4.title('Online Banking System')
root4.geometry('600x500+400+100')
root4.configure(bg='teal')
Label(root4,text='Easy Money Transfer System',bg='teal',fg='yellow',font='arial
18 bold italic').place(x=120,y=20)
Label(root4,text='If you are a new user, register youself and get Rs. 1000
bonus',bg='teal',font='arial 12 italic').place(x=50,y=60)
Label(root4,text='Account No.',bg='teal',font='arial 14').place(x=20,y=100)
Label(root4,text='Name',bg='teal',font='arial 14').place(x=20,y=150)
Label(root4,text='Address',bg='teal',font='arial 14').place(x=20,y=200)
Label(root4,text='Contact No',bg='teal',font='arial 14').place(x=20,y=250)
Label(root4,text='user id/email',bg='teal',font='arial 14').place(x=20,y=300)
Label(root4,text='Password',bg='teal',font='arial 14').place(x=20,y=350)
a1=StringVar()
a2=StringVar()
a3=StringVar()
a4=StringVar()
a5=StringVar()
a6=StringVar()
Entry(root4,textvariable=a1,width=15,font='arial 12').place(x=250,y=100)
Entry(root4,textvariable=a2,width=15,font='arial 12').place(x=250,y=150)
Entry(root4,textvariable=a3,width=15,font='arial 12').place(x=250,y=200)
Entry(root4,textvariable=a4,width=15,font='arial 12').place(x=250,y=250)
Entry(root4,textvariable=a5,width=15,font='arial 12').place(x=250,y=300)
Entry(root4,textvariable=a6,width=15,font='arial 12').place(x=250,y=350)
def signup():
actno=a1.get()
name=a2.get()
ad=a3.get()
contno=a4.get()
uid=a5.get()
pw=a6.get()
bl=1000.00
query='insert into
customer(acctno,name,address,contactno,userid,password,balance) values(%s,%s,%s,%s,
%s,%s,%s)'
mycur.execute(query,(actno,name,ad,contno,uid,pw,bl))
conn.commit()
messagebox.showinfo('Congrats','You have been registered!, now you can
login to use it')
close()
main()
def close():
root4.destroy()
def clear():
a1.set('')
a2.set('')
a3.set('')
a4.set('')
Button(root4,text='Register',command=signup,bg='teal',font='arial 12
bold').place(x=150,y=400)
Button(root4,text='Clear',command=clear,width=8,bg='teal',font='arial 12
bold').place(x=250,y=400)
Button(root4,text='Close',command=close,width=8,bg='teal',font='arial 12
bold').place(x=350,y=400)
root4.mainloop()
# for transaction
def transaction():
root3 =Tk()
root3.title('Online Banking System')
root3.geometry('600x500+400+100')
root3.configure(bg='teal')
Label(root3,text='Easy Money Transfer System',bg='teal',fg='yellow',font='arial
18 bold italic').place(x=120,y=20)
Label(root3,text='Direct Account Transfer',bg='teal',fg='yellow',font='arial 16
bold').place(x=180,y=60)
Label(root3,text='Reciever Account No.',bg='teal',font='arial
14').place(x=20,y=150)
Label(root3,text='Reciever Name',bg='teal',font='arial 14').place(x=20,y=200)
Label(root3,text='IFSC No',bg='teal',font='arial 14').place(x=20,y=250)
Label(root3,text='Amount to be Transfer',bg='teal',font='arial
14').place(x=20,y=300)
Label(root3,text='Enter OTP',bg='teal',font='arial 14').place(x=20,y=350)
a1=StringVar()
a2=StringVar()
a3=StringVar()
a4=StringVar()
a5=StringVar()
Entry(root3,textvariable=a1,width=15,font='arial 12').place(x=250,y=150)
Entry(root3,textvariable=a2,width=15,font='arial 12').place(x=250,y=200)
Entry(root3,textvariable=a3,width=15,font='arial 12').place(x=250,y=250)
Entry(root3,textvariable=a4,width=15,font='arial 12').place(x=250,y=300)
Entry(root3,textvariable=a5,width=15,font='arial 12').place(x=250,y=350)
#function to transfer money
def transferOther():
otp=random.randint(1111,9999)
messagebox.showinfo('OTP','OTP '+str(otp)+' has been sent to your
registered Number')
mycur.execute('select balance from customer where userid=%s',(uid,))
rec=mycur.fetchall()
b=rec[0][0]
balance=b
a5.set(str(otp))
actno=a1.get()
name=a2.get()
ifsc=a3.get()
blnc=float(a4.get())
if a5.get()==str(otp):
balance=balance-blnc
mycur.execute('update customer set balance=%s where userid=%s',
(balance,user,))
conn.commit()
clear()
Label(root3,text='Rs.'+str(blnc)+' has been Transferred to '+name+'
Account No. '+actno+'\nFor confirmation please check your account
balance',fg='yellow',bg='teal',font='arial 14 italic').place(x=20,y=400)
else:
messagebox.showinfo('Sorry','Wrong OTP')
a5.set('')
def chk_blnc():
mycur.execute('select balance from customer where userid=%s',(uid,))
rec=mycur.fetchall()
b=rec[0][0]
balance=b
v1=StringVar()
Label(root3,text='Opening Balance Amount:Rs.',bg='teal',font='arial 16
bold').place(x=50,y=100)
Label(root3,textvariable=v1,bg='teal',font='arial 16
bold').place(x=350,y=100)
v1.set(balance)
def close():
root3.destroy()
def transferOwn():
mycur.execute('select balance from customer where userid=%s',(uid,))
rec=mycur.fetchall()
b=rec[0][0]
balance=b
actno=a1.get()
name=a2.get()
ifsc=a3.get()
blnc=float(a4.get())
balance=balance+blnc
mycur.execute('update customer set balance=%s where userid=%s',
(balance,user,))
conn.commit()
clear()
Label(root3,text='Rs.'+str(blnc)+' has been deposited to youraccount\nFor
confirmation please check your account balance',fg='yellow',bg='teal',font='arial
14 italic').place(x=20,y=400)
def previous():
close()
options()
def clear():
a1.set('')
a2.set('')
a3.set('')
a4.set('')
a5.set('')
Button(root3,text='Transfer 2
other',command=transferOther,bg='teal',font='arial 12 bold').place(x=50,y=400)
Button(root3,text='Transfer 2 own',command=transferOwn,bg='teal',font='arial 12
bold').place(x=200,y=400)
Button(root3,text='Check Balane',command=chk_blnc,bg='teal',font='arial 12
bold').place(x=350,y=400)
Button(root3,text='Log out',command=close,width=8,bg='teal',font='arial 12
bold').place(x=450,y=150)
Button(root3,text='<-- Back',command=previous,width=8,bg='teal',font='arial 12
bold').place(x=450,y=200)
root3.mainloop()
#for profile
def profile():
root2 =Tk()
root2.title('Online Banking System')
root2.geometry('600x500+400+100')
root2.configure(bg='teal')
Label(root2,text='Easy Money Transfer System',bg='teal',fg='yellow',font='arial
18 bold italic').place(x=120,y=20)
Label(root2,text='CUSTOMER PROFILE',bg='teal',fg='yellow',font='arial 16
bold').place(x=180,y=100)
Label(root2,text='Account No.',bg='teal',font='arial 14').place(x=20,y=150)
Label(root2,text='Name',bg='teal',font='arial 14').place(x=20,y=200)
Label(root2,text='Address',bg='teal',font='arial 14').place(x=20,y=250)
Label(root2,text='Contact No',bg='teal',font='arial 14').place(x=20,y=300)
v1=StringVar()
v2=StringVar()
v3=StringVar()
v4=StringVar()
e1=Label(root2,textvariable=v1,width=20,font='arial 12').place(x=200,y=150)
e2=Entry(root2,textvariable=v2,width=20,font='arial 12').place(x=200,y=200)
e3=Entry(root2,textvariable=v3,width=20,font='arial 12').place(x=200,y=250)
e4=Entry(root2,textvariable=v4,width=20,font='arial 12').place(x=200,y=300)
#function to display profile
def show():
mycur.execute('select acctno,name,address,contactno from customer where
userid=%s',(uid,))
rec=mycur.fetchall()
v1.set(rec[0][0])
v2.set(rec[0][1])
v3.set(rec[0][2])
v4.set(rec[0][3])
#print(uid)
def update():
add=v3.get()
contact=v4.get()
mycur.execute('update customer set address=%s,contactno=%s where userid=
%s',(add,contact,user))
conn.commit()
messagebox.showinfo('Congrats!','Your profile has been updated')
def close():
root2.destroy()
def clear():
v1.set('')
v2.set('')
v3.set('')
v4.set('')
def previous():
close()
options()
Button(root2,text='Profile Details',command=show,bg='teal',font='arial 12
bold').place(x=50,y=360)
Button(root2,text='Update',command=update,bg='teal',font='arial 12
bold').place(x=200,y=360)
Button(root2,text='Clear',command=clear,width=8,bg='teal',font='arial 12
bold').place(x=300,y=360)
Button(root2,text='Log out',command=close,width=8,bg='teal',font='arial 12
bold').place(x=425,y=360)
Button(root2,text='<-- Back',command=previous,width=8,bg='teal',font='arial 12
bold').place(x=425,y=300)
root2.mainloop()
def options():
root1 =Tk()
root1.title('Online Banking System')
root1.geometry('600x500+400+100')
root1.configure(bg='teal')
Label(root1,text='Easy Money Transfer System',bg='teal',fg='yellow',font='arial
18 bold italic').place(x=120,y=20)
Label(root1,text='Instructions:\n 1. User can view or update theirs profile.'
'\n2. Customer can not update thier Account No and Name',bg='teal',font='arial 14
bold italic').place(x=20,y=100)
def close():
root1.destroy()
def profile_close():
close()
profile()
def transaction_close():
close()
transaction()
Button(root1,text='My
Profile',command=profile_close,width=25,bg='teal',font='arial 12
bold').place(x=200,y=250)

Button(root1,text='Transaction',command=transaction_close,width=25,bg='teal',font='
arial 12 bold').place(x=200,y=300)
Button(root1,text='Log out',command=close,width=25,bg='teal',font='arial 12
bold').place(x=200,y=350)
root1.mainloop()
def main():
root =Tk()
root.title('Online Banking System for KV2 Armapur')
root.geometry('650x500+300+100')
root.configure(bg='teal')
Label(root,text='Easy Money Transfer System',bg='teal',fg='yellow',font='arial
18 bold italic').place(x=120,y=20)
Label(root,text='User ID',bg='teal',font='arial 14').place(x=20,y=200)
Label(root,text='Password.',bg='teal',font='arial 14').place(x=20,y=240)
v1=StringVar()
v2=StringVar()
e1=Entry(root,textvariable=v1,width=20,font='arial 12').place(x=200,y=200)
e2=Entry(root,textvariable=v2,show='*',width=20,font='arial
12').place(x=200,y=240)

def close():
root.destroy()
def login():
global uid
uid=v1.get()
pw=v2.get()
mycur.execute('select * from customer where userid=%s',(uid,))
rec=mycur.fetchall()
global user
for i in rec:
user=i[0]
password=i[1]
if uid==user and pw==password:
close()
options()
else:
messagebox.showinfo('Sorry','Try again')
def register_close():
close()
register()
def clear():
v1.set('')
v2.set('')
Button(root,text='New User? SIGN
UP',command=register_close,bg='teal',font='arial 12 bold italic').place(x=10,y=300)
Button(root,text='Log in',command=login,width=8,bg='teal',font='arial 12
bold').place(x=200,y=300)
Button(root,text='Clear',command=clear,width=8,bg='teal',font='arial 12
bold').place(x=300,y=300)
Button(root,text='Close',command=close,width=8,bg='teal',font='arial 12
bold').place(x=400,y=300)
Label(root,text='Note:\n Its educational project, Used for Teaching
Only',bg='teal',fg='yellow',font='arial 10 bold
italic',justify=LEFT).place(x=10,y=420)
Label(root,text='KV NO.2 ARMAPUR KANPUR',bg='teal',fg='yellow',font='arial 12
bold italic',justify=RIGHT).place(x=10,y=350)
root.mainloop()

if __name__== main():
main()

You might also like