2021-11-04 15:07:47 +03:00
|
|
|
import customtkinter
|
2022-11-06 16:40:15 +03:00
|
|
|
from PIL import Image
|
2021-11-04 15:07:47 +03:00
|
|
|
import os
|
|
|
|
|
2022-11-06 16:40:15 +03:00
|
|
|
customtkinter.set_appearance_mode("dark")
|
2021-11-04 15:07:47 +03:00
|
|
|
|
|
|
|
|
2021-12-31 21:07:53 +03:00
|
|
|
class App(customtkinter.CTk):
|
2022-11-28 01:51:42 +03:00
|
|
|
width = 900
|
|
|
|
height = 600
|
2021-11-04 15:07:47 +03:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2022-01-07 22:54:45 +03:00
|
|
|
super().__init__(*args, **kwargs)
|
2021-11-04 15:07:47 +03:00
|
|
|
|
2022-11-28 01:51:42 +03:00
|
|
|
self.title("CustomTkinter example_background_image.py")
|
|
|
|
self.geometry(f"{self.width}x{self.height}")
|
2022-05-27 01:30:06 +03:00
|
|
|
self.resizable(False, False)
|
2021-11-04 15:07:47 +03:00
|
|
|
|
2022-11-28 01:51:42 +03:00
|
|
|
# load and create background image
|
2022-11-06 16:40:15 +03:00
|
|
|
current_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
self.bg_image = customtkinter.CTkImage(Image.open(current_path + "/test_images/bg_gradient.jpg"),
|
2022-11-28 01:51:42 +03:00
|
|
|
size=(self.width, self.height))
|
|
|
|
self.bg_image_label = customtkinter.CTkLabel(self, image=self.bg_image)
|
|
|
|
self.bg_image_label.grid(row=0, column=0)
|
|
|
|
|
|
|
|
# create login frame
|
|
|
|
self.login_frame = customtkinter.CTkFrame(self, corner_radius=0)
|
|
|
|
self.login_frame.grid(row=0, column=0, sticky="ns")
|
|
|
|
self.login_label = customtkinter.CTkLabel(self.login_frame, text="CustomTkinter\nLogin Page",
|
|
|
|
font=customtkinter.CTkFont(size=20, weight="bold"))
|
|
|
|
self.login_label.grid(row=0, column=0, padx=30, pady=(150, 15))
|
|
|
|
self.username_entry = customtkinter.CTkEntry(self.login_frame, width=200, placeholder_text="username")
|
|
|
|
self.username_entry.grid(row=1, column=0, padx=30, pady=(15, 15))
|
|
|
|
self.password_entry = customtkinter.CTkEntry(self.login_frame, width=200, show="*", placeholder_text="password")
|
|
|
|
self.password_entry.grid(row=2, column=0, padx=30, pady=(0, 15))
|
|
|
|
self.login_button = customtkinter.CTkButton(self.login_frame, text="Login", command=self.login_event, width=200)
|
|
|
|
self.login_button.grid(row=3, column=0, padx=30, pady=(15, 15))
|
|
|
|
|
|
|
|
# create main frame
|
|
|
|
self.main_frame = customtkinter.CTkFrame(self, corner_radius=0)
|
|
|
|
self.main_frame.grid_columnconfigure(0, weight=1)
|
|
|
|
self.main_label = customtkinter.CTkLabel(self.main_frame, text="CustomTkinter\nMain Page",
|
|
|
|
font=customtkinter.CTkFont(size=20, weight="bold"))
|
|
|
|
self.main_label.grid(row=0, column=0, padx=30, pady=(30, 15))
|
|
|
|
self.back_button = customtkinter.CTkButton(self.main_frame, text="Back", command=self.back_event, width=200)
|
|
|
|
self.back_button.grid(row=1, column=0, padx=30, pady=(15, 15))
|
|
|
|
|
|
|
|
def login_event(self):
|
|
|
|
print("Login pressed - username:", self.username_entry.get(), "password:", self.password_entry.get())
|
|
|
|
|
|
|
|
self.login_frame.grid_forget() # remove login frame
|
|
|
|
self.main_frame.grid(row=0, column=0, sticky="nsew", padx=100) # show main frame
|
|
|
|
|
|
|
|
def back_event(self):
|
|
|
|
self.main_frame.grid_forget() # remove main frame
|
|
|
|
self.login_frame.grid(row=0, column=0, sticky="ns") # show login frame
|
2021-11-04 15:07:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app = App()
|
2022-11-28 01:18:10 +03:00
|
|
|
app.mainloop()
|