Code:
from tkinter import *
from tkinter import ttk
from tkinter import messagebox as ms
import datetime
class Gui:
def __init__(self):
self.window = Tk()
self.window.title("School Life!")
self.window.geometry("1024x768")
self.window.configure(background="azure")
self.username = StringVar()
self.password = StringVar()
self.n_username = StringVar()
self.n_password = StringVar()
self.role = IntVar()
self.homescreen()
def menubar(self):
menu_bar = Menu(self.window)
options_menu = Menu(menu_bar, tearoff=0)
options_menu.add_command(label="Log Out", command=self.test)
options_menu.add_command(label="Quit", command=self.window.quit)
menu_bar.add_cascade(label="Options", menu=options_menu)
def test(self):
print("It works")
def na_homescreen_del(self):
self.window.destroy()
self.new_account_gui()
def mm_homescreen_del(self):
self.window.destroy()
self.mainmenu()
def tt_mainmenu_del(self):
self.mainmenu_window.destroy()
self.my_timetable()
def hw_mainmenu_del(self):
self.mainmenu_window.destroy()
self.my_homework()
def hs_newaccount_del(self):
self.new_acc_window.destroy()
self.homescreen()
def new_account_gui(self):
self.new_acc_window = Tk()
self.new_acc_window["padx"] = 5
self.new_acc_window["pady"] = 5
# Title and creation of label frame to contain widgets ----- "na" stands for 'new account'
header_label = Label(self.new_acc_window, text="The School Life App!", font=("", 30, "bold"))
header_label.pack(fill=X, side=TOP)
na_frame = LabelFrame(self.new_acc_window, text="Create A New Account", relief=RIDGE)
na_frame.pack(side=LEFT, fill=BOTH, expand=True)
# Creation of labels
na_username_label = Label(na_frame, text="Username")
na_username_label.grid(row=2, column=2, sticky=W, pady=3)
na_password_label = Label(na_frame, text="Password")
na_password_label.grid(row=3, column=2, sticky=W, pady=3)
# Creation of entry widgets for the user to enter their new user credentials
na_username_entry = Entry(na_frame, width=30, textvariable=self.n_username)
na_username_entry.grid(row=2, column=3, sticky=W, pady=3)
na_password_entry = Entry(na_frame, width=30, textvariable=self.n_password, show="*")
na_password_entry.grid(row=2, column=3, sticky=W, pady=3)
# Creation of buttons
na_login_button = ttk.Button(na_frame, text="Go Back", width=10, command=self.hs_newaccount_del())
na_login_button.grid(row=4, column=2)
na_create_new_button = ttk.Button(na_frame, text="Create New Account", width=12, command=self.test) # This needs to change to put the user inputs as the username and password.
na_create_new_button.grid(row=4, column=3)
na_quit_button = ttk.Button(na_frame, text="Quit", width=12, command=self.new_acc_window.quit)
na_quit_button.grid(row=4, column=3)
na_current_date = str(datetime.datetime.now().date)
na_date_entry = Entry(na_frame, width=10, textvariable=na_current_date)
na_date_entry.grid(row=0, column=10)
def homescreen(self):
self.window["padx"] = 5
self.window["pady"] = 5
# Title and creation of label frame to contain widgets ----- "hs" stands for 'home screen'
header_label = Label(self.window, text="The School Life App!", font=("", 30, "bold"))
header_label.pack(fill=X)
hs_frame = LabelFrame(self.window, text="Log In", labelanchor=N, relief=RIDGE)
hs_frame.pack(side=LEFT, fill=BOTH, expand=True)
# Creation of labels
hs_username_label = Label(hs_frame, text="Username", font=("", 15))
hs_username_label.grid(row=25, column=23, sticky=W, pady=3)
hs_password_label = Label(hs_frame, text="Password", font=("", 15))
hs_password_label.grid(row=26, column=23, sticky=W, pady=3)
# Creation of entry widgets for the user to enter their log in details
hs_username_entry = Entry(hs_frame, width=15, textvariable=self.username)
hs_username_entry.grid(row=25, column=24, sticky=W, pady=3)
hs_password_entry = Entry(hs_frame, width=15, textvariable=self.password, show="*")
hs_password_entry.grid(row=26, column=24, sticky=W, pady=3)
# Creation of buttons
hs_login_button = ttk.Button(hs_frame, text="Sign In", width=30, command=self.mm_homescreen_del())
hs_login_button.grid(row=30, column=19)
hs_create_new_button = ttk.Button(hs_frame, text="Create New Account", width=30, command=self.na_homescreen_del())
hs_create_new_button.grid(row=30, column=22)
hs_quit_button = ttk.Button(hs_frame, text="Quit", width=40, command=self.window.quit)
hs_quit_button.grid(row=30, column=25)
hs_date_label = Label(hs_frame, text=datetime.datetime.now().strftime('%d-%m-%Y'))
hs_date_label.grid(row=1, column=0)
menu_bar = Menu(self.window)
options_menu = Menu(menu_bar, tearoff=0)
options_menu.add_command(label="Log Out", command=self.test)
options_menu.add_command(label="Quit", command=self.window.quit)
menu_bar.add_cascade(label="Options", menu=options_menu)
def mainmenu(self):
self.mainmenu_window = Tk()
self.mainmenu_window["padx"] = 5
self.mainmenu_window["pady"] = 5
header_label = Label(self.mainmenu_window, text="The School Life App!", font=("", 30, "bold"))
header_label.pack(fill=X)
mm_frame = LabelFrame(self.mainmenu_window, text="Main Menu", relief=RIDGE)
mm_frame.pack(side=LEFT, fill=BOTH, expand=TRUE)
# Creation of buttons
mm_timetable_button = ttk.Button(mm_frame, text="My Timetable", width=500, command=self.test)
mm_timetable_button.grid(row=1, column=1)
mm_homework_button = ttk.Button(mm_frame, text="My Homework", width=500, command=self.test)
mm_homework_button.grid(row=1, column=2)
mm_classes_button = ttk.Button(mm_frame, text="My Classes", width=500, command=self.test)
mm_classes_button.grid(row=1, column=3)
def my_timetable(self):
self.timetable_window = Tk()
self.timetable_window.title(self.username.get() + "'s Timetable")
tt_frame = LabelFrame(self.timetabel_window, text="Timetable", relief=RIDGE)
tt_frame.pack(side=LEFT, fill=BOTH, expand=TRUE)
def my_homework(self):
self.
program = Gui()
program.window.mainloop()
need to add a few more functions and connect this to my database python file, but im not too sure where the code is breaking (also thanks for the reply)