Project
unknown
python
3 years ago
3.1 kB
9
Indexable
from tkinter import *
import tkinter.filedialog as ask
import tkinter.messagebox as mb
import os
import webbrowser
from abc import ABC, abstractmethod
class Window(ABC):
def __init__(self,win = None):
self.win = win
self.win = Tk()
self.win.geometry('300x400')
self.win.title('Contact Book')
self.win.config(bg='grey')
self.label = Label(self.win, text="CONTACTBOOK", font=('arial', 20)).place(x=70, y=10)
self.contact = [['','','','',''],]
self.name = StringVar()
self.num = StringVar()
self.email = StringVar()
self.instagram = StringVar()
self.facebook = StringVar()
Button(self.win,text=" ADD",bg='White',fg= 'Black', command = self.add).place(x= 120, y=50)
Button(self.win,text="VIEW",bg='White',fg='Black', command = self.view).place(x= 120, y=100)
Button(self.win,text="CLEAR",bg='White',fg='Black', command = self.clear).place(x= 120, y=150)
Button(self.win,text="EXIT",bg='red',fg='red', command = self.quit).place(x= 120, y=300)
self.win.mainloop()
@abstractmethod
def add(self):
pass
@abstractmethod
def view(self):
pass
@abstractmethod
def clear(self):
pass
@abstractmethod
def quit(self):
pass
class insidecommand(Window):
def enter(self):
with open("database.csv", "a") as f:
f.write(f"{self.name.get()},{self.num.get()},{self.email.get()},{self.instagram.get()},{self.facebook.get()}\n")
self.add.destroy()
class Contact(insidecommand, Window):
def __init__(self, win= None):
super().__init__(win)
# self.add()
def add(self):
self.add = Toplevel(self.win)
self.add.title("ADD")
self.add.config(bg='#722F37')
Label(self.add, text="Name: ", bg='#722F37').grid(row=0, column=0)
Entry(self.add, textvariable=self.name).grid(row=0, column=1)
Label(self.add, text="Number: ", bg='#722F37').grid(row=1, column=0)
Entry(self.add, textvariable=self.num).grid(row=1, column=1)
Label(self.add, text="Email: ", bg='#722F37').grid(row=2, column=0)
Entry(self.add, textvariable=self.email).grid(row=2, column=1)
Label(self.add, text="Instagram: ", bg='#722F37').grid(row=3, column=0)
Entry(self.add, textvariable=self.instagram).grid(row=3, column=1)
Label(self.add, text="Facebook: ", bg='#722F37').grid(row=4, column=0)
Entry(self.add, textvariable=self.facebook).grid(row=4, column=1)
Button(self.add, text="Enter", bg='#722F37', command=self.enter).grid(row=5,column=1,sticky=E)
def view(self):
self.view = Toplevel(self.win)
self.view.title("VIEW")
self.view.geometry('600x500')
self.view.config(bg='#023020')
def clear(self):
with open("database.csv", 'w') as f:
f.write('')
def quit(self):
self.win.destroy()
if __name__ == '__main__':
Contact()Editor is loading...