There are Three code files
Main.py :-
from tkinter import *
from tkinter.ttk import *
from tkinter import messagebox
from sqlite3 import *
from turtle import home
import home
class LoginWindow(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
self.title("login")
self.geometry("400x300")
s = Style()
s.configure('Header.TFrame', background = 'blue')
header_frame = Frame(self, style= 'Header.TFrame')
header_frame.pack(fill = X)
s.configure('Header.TLabel', background = 'blue', foreground = 'white', font = ('Arial', 25))
header_label = Label(header_frame,text="Office contact book", style='Header.TLabel')
header_label.pack(pady=10)
s.configure('Content.TFrame', background = 'white')
content_frame = Frame(self, style= 'Content.TFrame')
content_frame.pack(fill= BOTH, expand= TRUE)
login_frame = Frame(content_frame, style= 'Content.TFrame')
login_frame.place(relx=.5, rely=.5, anchor=CENTER)
s.configure('Login.TLabel', background = 'white', font = ('Arial', 15))
username_label = Label(login_frame, text= 'Username:', style= 'Login.TLabel')
username_label.grid(row= 0, column= 0, pady= 5)
self.username_entry = Entry(login_frame,width= 15, font = ('Arial', 15))
self.username_entry.grid(row= 0, column= 1, pady= 5)
password_label = Label(login_frame, text= 'Password:', style= 'Login.TLabel')
password_label.grid(row= 1, column= 0, pady= 5)
self.password_entry = Entry(login_frame,width= 15, font = ('Arial', 15), show= '*')
self.password_entry.grid(row= 1, column= 1, pady= 5)
s.configure("Login.TButton", font = ('Arial', 15))
login_button = Button(login_frame, text ="Login",width= 15, style= 'Login.TButton', command= self.login_button_click)
login_button.grid(row=3, column= 1, pady= 5)
def login_button_click(self):
con = connect('contacts.db')
cur = con.cursor()
cur.execute("select * from Login where Username = ? and Password = ?", (self.username_entry.get(), self.password_entry.get()))
row = cur.fetchone()
if row is not None:
self.destroy()
home.HomeWindow()
else:
messagebox.showerror("Error message", "Incorrect username or password.")
if __name__ == '__main__':
lw = LoginWindow()
lw.mainloop()
Home.py :-
from tkinter import *
from tkinter.ttk import *
from tkinter import messagebox
from sqlite3 import *
from turtle import width
import main
import changepassword
class HomeWindow (Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
self.title("Home")
self.state('zoomed')
s = Style()
s.configure('Header.TFrame', background = 'blue')
header_frame = Frame(self, style= 'Header.TFrame', height= 50)
header_frame.pack(fill = X)
s.configure('Header.TLabel', background = 'blue', foreground = 'white', font = ('Arial', 25))
header_label = Label(header_frame,text="Office contact book", style='Header.TLabel')
header_label.pack(pady=10)
navigation_frame = Frame(self, style= 'Header.TFrame', width= 50)
navigation_frame.pack(side= LEFT, fill= Y)
s.configure('Navigation.TButton', width= 30, font= ('Arial', 15))
manage_contacts_button = Button(navigation_frame, text= 'Manage contacts', style= 'Navigation.TButton')
manage_contacts_button.pack(ipady= 10, pady= 2)
def change_password_button_click (self):
changepassword.ChangePasswordFrame(content_frame)
change_password_button = Button(navigation_frame, text= 'Change password', style= 'Navigation.TButton', command= self.change_password_button_click(*args))
change_password_button.pack(ipady= 10, pady= 2)
def logout_button_click (self):
self.destroy()
main.LoginWindow()
# logout_button = Button(navigation_frame, text= 'Logout', style= 'Navigation.TButton', command= self.logout_button_click)
# logout_button.pack(ipady= 10, pady= 2)
s.configure('Navigation.TFrame', background = 'white')
content_frame = Frame(self, style= 'Navigation.TFrame')
content_frame.pack(fill= BOTH, expand= TRUE)
# lw = HomeWindow()
# lw.mainloop()
changepassword.py :-
from tkinter import *
from tkinter.ttk import *
class ChangePasswordFrame (Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
s = Style()
s.configure('TFrame', background = 'white')
s.configure('TLabel', background = 'white', font = ('Arial', 25))
self.place(relx = .5, rely = .5, anchor = CENTER)
old_password_label = Label(self, text= "Old Password:")
old_password_label.grid(row=0, column= 0)
old_password_entry = Entry(self)
old_password_entry.grid(row=0, column=1)
New_password_label = Label(self, text= "New Password:")
New_password_label.grid(row=1, column= 0)
New_password_entry = Entry(self)
New_password_entry.grid(row=1, column=1)
confrim_password_label = Label(self, text= "Confrim new Password:")
confrim_password_label.grid(row=2, column= 0)
confrim_password_entry = Entry(self)
confrim_password_entry.grid(row=2, column=1)
change_password_button = Button(self, text = "Change Password")
change_password_button.grid(row = 3, column = 1)
the error i get is: -
[Running] python -u "g:\Projects\Coding\Python\Folder files\xomtact book\main.py"
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Sandeep Sharma\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "g:\Projects\Coding\Python\Folder files\xomtact book\main.py", line 63, in login_button_click
home.HomeWindow()
File "g:\Projects\Coding\Python\Folder files\xomtact book\home.py", line 38, in __init__
change_password_button = Button(navigation_frame, text= 'Change password', style= 'Navigation.TButton', command= self.change_password_button_click)
File "C:\Users\Sandeep Sharma\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 2383, in __getattr__
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute 'change_password_button_click'
PLEASE HELP ME I'M STUCK WITH THIS PEICE OF CODE
BTW my name is Vedant