fl_cutof / main.py
PetrovDE's picture
add first income
886303d
import customtkinter
import os
from PIL import Image
class App(customtkinter.CTk):
def __init__(self):
super().__init__()
self.title("ОтрубИ")
self.geometry("700x450")
# set grid layout 1x2
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(1, weight=1)
# create navigation frame
self.navigation_frame = customtkinter.CTkFrame(self, corner_radius=0)
self.navigation_frame.grid(row=0, column=0, sticky="nsew")
self.navigation_frame.grid_rowconfigure(4, weight=1)
self.navigation_frame_label = customtkinter.CTkLabel(
self.navigation_frame,
text="Главное меню",
compound="left",
font=customtkinter.CTkFont(size=15, weight="bold")
)
self.navigation_frame_label.grid(row=0, column=0, padx=20, pady=20)
self.home_button = customtkinter.CTkButton(
self.navigation_frame,
corner_radius=0,
height=40,
border_spacing=10,
text="Обработка строк",
fg_color="transparent",
text_color=("gray10", "gray90"),
hover_color=("gray70", "gray30"),
anchor="w",
command=self.home_button_event)
self.home_button.grid(row=1, column=0, sticky="ew")
self.frame_2_button = customtkinter.CTkButton(
self.navigation_frame,
corner_radius=0,
height=40,
border_spacing=10,
text="Обработка документа",
fg_color="transparent",
text_color=("gray10", "gray90"),
hover_color=("gray70", "gray30"),
anchor="w",
command=self.frame_2_button_event)
self.frame_2_button.grid(row=2, column=0, sticky="ew")
self.appearance_mode_menu = customtkinter.CTkOptionMenu(self.navigation_frame, values=["Light", "Dark", "System"],
command=self.change_appearance_mode_event)
self.appearance_mode_menu.grid(row=6, column=0, padx=20, pady=20, sticky="s")
# create home frame
self.home_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent")
self.home_frame.grid_columnconfigure(0, weight=1)
self.home_frame_label = customtkinter.CTkLabel(self.home_frame, text="Преобразование текста")
self.home_frame_label.grid(row=0, column=0, padx=20, pady=10)
self.home_text_in = customtkinter.CTkTextbox(self.home_frame, width=400, height=150, corner_radius=0)
self.home_text_in.grid(row=1, column=0, padx=10, pady=10)
self.home_text_in.insert("0.0", "Текст для преобразования")
self.home_frame_button_process = customtkinter.CTkButton(self.home_frame, text="Process", compound="right", command=self.button_process_event)
self.home_frame_button_process.grid(row=2, column=0, padx=10, pady=10)
self.home_text_out = customtkinter.CTkTextbox(self.home_frame, width=400, height=150, corner_radius=0)
self.home_text_out.grid(row=3, column=0, padx=10, pady=10)
self.home_text_out.insert("0.0", "Текст после преобразования")
# create second frame
self.second_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent")
# create third frame
self.third_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent")
# select default frame
self.select_frame_by_name("home")
def select_frame_by_name(self, name):
# set button color for selected button
self.home_button.configure(fg_color=("gray75", "gray25") if name == "home" else "transparent")
self.frame_2_button.configure(fg_color=("gray75", "gray25") if name == "frame_2" else "transparent")
# show selected frame
if name == "home":
self.home_frame.grid(row=0, column=1, sticky="nsew")
else:
self.home_frame.grid_forget()
if name == "frame_2":
self.second_frame.grid(row=0, column=1, sticky="nsew")
else:
self.second_frame.grid_forget()
def button_process_event(self):
self.home_text_out.delete("0.0", "end-1c")
self.home_text_out.insert("0.0", f"{self.home_text_in.get("0.0", "end-1c")} - после преобразования")
def home_button_event(self):
self.select_frame_by_name("home")
def frame_2_button_event(self):
self.select_frame_by_name("frame_2")
def change_appearance_mode_event(self, new_appearance_mode):
customtkinter.set_appearance_mode(new_appearance_mode)
if __name__ == "__main__":
app = App()
app.mainloop()