Python Micro
Python Micro
1
lOMoAR cPSD| 37250859
MAHARASHTRA STATE
BOARD OF TECHNICAL
EDUCATION
Certificate
This is to certify that Mr. NILWARN SUMIT D, JADHAV ROHIT ,R,DAHIWAL OMKAR S,
Roll No.C0334,CO338,CO341 of 5th Semester of Diploma in COMPUTER
Place: JIINTUR
Date:
2
lOMoAR cPSD| 37250859
ABSTRACT
3
lOMoAR cPSD| 37250859
INDEX
1) 3
Introduction
2) 5
CONTACT BOOK DETAILS
4) PROGRAM OF CONATCT 17
BOOK
5) 24
OUPTUTS
6) 25
CONCLUSION
7) 25
REFERENCE
4
lOMoAR cPSD| 37250859
Introduction
5
lOMoAR cPSD| 37250859
We can add new contacts by clicking on the add button and filling in the
information of the new contact. We can update or edit existing contacts
by selecting and clicking on the edit button. Similarly, we can delete and
view the contact. Like this, we can store data.
6
lOMoAR cPSD| 37250859
1. Import Modules
2. Initializing the window
3. Create frame
4. Function to get select value
5. Function to add new contact and edit existing contact
6. Function to delete and view contact
7. Exit the game window
8. Define buttons labels and entry widget
7
lOMoAR cPSD| 37250859
8
lOMoAR cPSD| 37250859
['Ganesh Pawar','85967412']
]
Name = StringVar()
Number = StringVar()
Code Explanation-
root – Initializing the root window of Python contact book Project.
.title – Use to set title to window.
.geometry – For setting dimensions of a window in pixels.
.config – Used to configure attributes to the window, such as
back- ground color.
contactlist – For storing a database of the project in the list in
name and phone number format.
Step 3- Create frame
#PythonGeeks - create frame
frame = Frame(root)
frame.pack(side = RIGHT)
scroll = Scrollbar(frame, orient=VERTICAL)
select = Listbox(frame, yscrollcommand=scroll.set, font=('Times new
roman' ,16), bg="#f0fffc", width=20, height=20, borderwidth=3, relief=
"groove")
scroll.config (command=select.yview)
9
lOMoAR cPSD| 37250859
scroll.pack(side=RIGHT, fill=Y)
select.pack(side=LEFT, fill=BOTH, expand=1)
Code Explanation-
Frame – For creating a frame.
.pack() – This puts the widget inside the frame. And declare the
po- sition of the widget in relation with each other.
listbox – listbox is the tkinter toolkit used for displaying more than
one item.
scroll – Here we are creating a frame at the right side of the win-
dow which will show our listbox. And the scrollbar controls the
up and down moment of the listbox.
We are making a listbox and setting their font background
color, width, height, border width, and set command as scroll.
Step 4- Function to get select value
#PythonGeeks - function to get select value
def Selected():
print("hello",len(select.curselection()))
if len(select.curselection())==0:
messagebox.showerror("Error", "Please Select the Name")
else:
return int(select.curselection()[0])
10
lOMoAR cPSD| 37250859
Code Explanation-
Selected() – Function for selecting the values.
curselection() – curselection is the tkinter toolkit used for
display- ing the selected items.
len – Used to count the length of data.
If the length of curselection is equal to 0 means we don’t select
an- ything, then a message will pop up on the screen that says
“Error”, “Please Select the Name”.
Step 5- Function to add new contact and edit existing contact
#PythonGeeks -fun to add new contact
def AddContact():
if Name.get()!="" and Number.get()!="":
contactlist.append([Name.get() ,Number.get()])
print(contactlist)
Select_set()
EntryReset()
messagebox.showinfo("Confirmation", "Successfully Add New Con-
tact")
else:
messagebox.showerror("Error","Please fill the information")
def UpdateDetail():
11
lOMoAR cPSD| 37250859
12
lOMoAR cPSD| 37250859
13
lOMoAR cPSD| 37250859
14
lOMoAR cPSD| 37250859
15
lOMoAR cPSD| 37250859
Button(root,text="DELETE", font='Helvetica 18
bold',bg='#e8c1c7',command = Delete_Entry, padx=20).place(x= 50,
y=260)
Button(root,text="VIEW", font='Helvetica 18 bold',bg='#e8c1c7', com-
mand = VIEW).place(x= 50, y=325)
Button(root,text="RESET", font='Helvetica 18 bold',bg='#e8c1c7', com-
mand = EntryReset).place(x= 50, y=390)
Button(root,text="EXIT", font='Helvetica 24 bold',bg='tomato', com-
mand = EXIT).place(x= 250, y=470)
root.mainloop()
Code Explanation-
label – In this variable we use the label widget for displaying the
box in which we give text. Then call configure to set font, font
size, and background color.
Here we are creating buttons ADD, EDIT, DELETE, VIEW,
RE- SET, EXIT and setting their font, background color, and
setting proper position using the .place method.
16
lOMoAR cPSD| 37250859
PROGRAM:
#PythonGeeks - import library from
tkinter import *
from tkinter import messagebox
17
lOMoAR cPSD| 37250859
Name = StringVar()
Number = StringVar()
18
lOMoAR cPSD| 37250859
def Selected():
print("hello",len(select.curselection()))
if len(select.curselection())==0:
messagebox.showerror("Error", "Please Select the Name")
else:
return int(select.curselection()[0])
else:
messagebox.showerror("Error","Please fill the information")
19
lOMoAR cPSD| 37250859
def UpdateDetail():
if Name.get() and Number.get():
contactlist[Selected()] = [Name.get(),
Number.get()]
else:
if len(select.curselection())==0:
messagebox.showerror("Error", "Please Select the Name and \n
press Load button")
20
lOMoAR cPSD| 37250859
else:
message1 = """To Load the all information of \n
selected row press Load button\n.
"""
messagebox.showerror("Error", message1)
def EntryReset():
Name.set('')
Number.set('')
21
lOMoAR cPSD| 37250859
def Select_set() :
contactlist.sort()
select.delete(0,END)
for name,phone in contactlist :
select.insert (END, name)
Select_set()
22
lOMoAR cPSD| 37250859
root.mainloop()
23
lOMoAR cPSD| 37250859
OUTPUT:
24
lOMoAR cPSD| 37250859
CONCLUSION:
We have successfully created a python contact book pro-
ject using the Graphical user Interface(GUI). We have
learned about the Thinter module.
Reference:
1) www.google.com
2) www.chatgpt.com
25