From 014414a4412b0a3fd2efe0d5d252b7117b9c5df8 Mon Sep 17 00:00:00 2001 From: "Terence2.Frayne@live.uwe.ac.uk" <terence2.frayne@live.uwe.ac.uk> Date: Mon, 4 Nov 2024 12:37:59 +0000 Subject: [PATCH] Upload New File --- GUI.py | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 GUI.py diff --git a/GUI.py b/GUI.py new file mode 100644 index 0000000..c5fc2e5 --- /dev/null +++ b/GUI.py @@ -0,0 +1,93 @@ +from tkinter import Tk, Frame, Label, Entry, Button, messagebox + +# Initialize main window +window = Tk() +window.title("Login") +window.geometry('340x440') + +# Color for light and dark mode +light_mode = { + "bg": "#f0f0f0", + "fg": "#000000", + "button_bg": "#e0e0e0", + "button_fg": "#000000", + "entry_bg": "#ffffff", + "entry_fg": "#000000", +} +dark_mode = { + "bg": "#333333", + "fg": "#ffffff", + "button_bg": "#555555", + "button_fg": "#ffffff", + "entry_bg": "#444444", + "entry_fg": "#ffffff", +} + +# Initialize with dark mode +current_theme = dark_mode + +# Toggle between light and dark mode +def toggle_theme(): + global current_theme + if current_theme == dark_mode: + current_theme = light_mode + else: + current_theme = dark_mode + apply_theme() + +# Apply the selected theme to all widgets +def apply_theme(): + window.configure(bg=current_theme["bg"]) + form_frame.configure(bg=current_theme["bg"]) + login_label.configure(bg=current_theme["bg"], fg=current_theme["fg"]) + username_label.configure(bg=current_theme["bg"], fg=current_theme["fg"]) + password_label.configure(bg=current_theme["bg"], fg=current_theme["fg"]) + username_entry.configure(bg=current_theme["entry_bg"], fg=current_theme["entry_fg"]) + password_entry.configure(bg=current_theme["entry_bg"], fg=current_theme["entry_fg"]) + login_button.configure(bg=current_theme["button_bg"], fg=current_theme["button_fg"]) + theme_toggle_button.configure(bg=current_theme["button_bg"], fg=current_theme["button_fg"]) + +# Handle login action +def login(): + username = username_entry.get() + password = password_entry.get() + if not username or not password: + messagebox.showwarning("Warning", "Please fill in both fields.") + else: + messagebox.showinfo("Login", "Login successful!") + +# Make rows and columns in the main window expand to center the form frame +window.grid_rowconfigure(0, weight=1) +window.grid_rowconfigure(2, weight=1) +window.grid_columnconfigure(0, weight=1) +window.grid_columnconfigure(2, weight=1) + +# Login form in the center of the window +form_frame = Frame(window, bg=current_theme["bg"]) +form_frame.grid(row=1, column=1, padx=20, pady=20) + +# Widgets for login +login_label = Label(form_frame, text="Login", font=("Arial", 18), fg=current_theme["fg"], bg=current_theme["bg"]) +username_label = Label(form_frame, text="Username", fg=current_theme["fg"], bg=current_theme["bg"]) +username_entry = Entry(form_frame, width=25, bg=current_theme["entry_bg"], fg=current_theme["entry_fg"]) +password_label = Label(form_frame, text="Password", fg=current_theme["fg"], bg=current_theme["bg"]) +password_entry = Entry(form_frame, show="*", width=25, bg=current_theme["entry_bg"], fg=current_theme["entry_fg"]) +login_button = Button(form_frame, text="Login", command=login, bg=current_theme["button_bg"], fg=current_theme["button_fg"], width=20) + +# Button for Light/Dark Mode +theme_toggle_button = Button(form_frame, text="Toggle Light/Dark Mode", command=toggle_theme, + bg=current_theme["button_bg"], fg=current_theme["button_fg"]) + +# Place widgets on the screen +login_label.grid(row=0, column=0, columnspan=2, pady=(10, 10)) +username_label.grid(row=1, column=0, padx=5, pady=5, sticky="e") +username_entry.grid(row=1, column=1, padx=5, pady=5, sticky="w") +password_label.grid(row=2, column=0, padx=5, pady=5, sticky="e") +password_entry.grid(row=2, column=1, padx=5, pady=5, sticky="w") +login_button.grid(row=3, column=0, columnspan=2, pady=(10, 10)) +theme_toggle_button.grid(row=4, column=0, columnspan=2, pady=(10, 10)) + +# Enable to use theme +apply_theme() + +window.mainloop() -- GitLab