CRUD Operations using Tkinter

CRUD Operations using Tkinter

from tkinter import *

from pymongo import MongoClient

client = MongoClient('localhost', 27017)

db = client['mydatabase']

collection = db['students']

def insert():

    name = name_entry.get()

    email = email_entry.get()

    phone = phone_entry.get()

    collection.insert_one({'name': name, 'email': email, 'phone': phone})

    print('Data inserted successfully')

def update():

    name = name_entry.get()

    email = email_entry.get()

    phone = phone_entry.get()

    collection.update_one({'name': name}, {'$set': {'email': email, 'phone': phone}})

    print('Data updated successfully')

def delete():

    name = name_entry.get()

    collection.delete_one({'name': name})

    print('Data deleted successfully')

def read():

    data = collection.find()

    for record in data:

        print(record)

window=Tk()

window.title("Registration Form")

window.geometry("500x600")

name_label=Label(window,text="Registration Form",font=23).place(x=140,y=35)

 

name_label=Label(window,text="Name").place(x=40,y=75)

name_entry=Entry(window)

name_entry.place(x=170,y=75)

email_label=Label(window,text="Email").place(x=40,y=115)

email_entry=Entry(window)

email_entry.place(x=170,y=115)

phone_label=Label(window,text="Mobile Number").place(x=40,y=155)

phone_entry=Entry(window)

phone_entry.place(x=170,y=155)

usname_label=Label(window,text="Username").place(x=40,y=205)

usname_entry=Entry(window)

usname_entry.place(x=170,y=205)

password_label=Label(window,text="Password").place(x=40,y=255)

password_entry=Entry(window)

password_entry.place(x=170,y=255)

cpassword_label=Label(window,text="Confirm Password").place(x=40,y=300)

cpassword_entry=Entry(window)

cpassword_entry.place(x=170,y=300)

insert_button=Button(window,text="Insert",command=insert)

insert_button.place(x=40,y=355)

update_button=Button(window,text="Update",command=update)

update_button.place(x=110,y=355)

delete_button=Button(window,text="Delete",command=delete)

delete_button.place(x=180,y=355)

read_button=Button(window,text="Select All",command=read)

read_button.place(x=250,y=355)

window.mainloop()


Comments

Popular posts from this blog

DS - Representation of linked list in memory.

Cpp- Program for call by reference

NUMERICAL ABILITY