Browse Source

#4 Sidebar in eigenes Element gepackt

master
Eddie 2 years ago
parent
commit
d706adc78b
  1. 52
      app.py
  2. 0
      elements/__init__.py
  3. 52
      elements/sidebar.py

52
app.py

@ -1,7 +1,9 @@
import tkinter import tkinter
import tkinter.messagebox import tkinter.messagebox
import customtkinter import customtkinter
from elements.sidebar import sidebar
# General Setup
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light" customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue" customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
@ -19,53 +21,10 @@ class App(customtkinter.CTk):
self.grid_columnconfigure((2, 3), weight=0) self.grid_columnconfigure((2, 3), weight=0)
self.grid_rowconfigure((0, 1, 2), weight=1) self.grid_rowconfigure((0, 1, 2), weight=1)
# create sidebar frame with widgets # Load Elements
self.sidebar_frame = customtkinter.CTkFrame(self, width=140, corner_radius=0) sidebar(self)
self.sidebar_frame.grid(row=0, column=0, rowspan=4, sticky="nsew")
self.sidebar_frame.grid_rowconfigure(9, weight=1)
# Logo
self.logo_label = customtkinter.CTkLabel(self.sidebar_frame, text="BudgetPy", font=customtkinter.CTkFont(size=20, weight="bold"))
self.logo_label.grid(row=0, column=0, padx=20, pady=(20, 10))
# Button Personen
self.sidebar_button_1 = customtkinter.CTkButton(self.sidebar_frame, text="Personen", command=self.sidebar_button_event)
self.sidebar_button_1.grid(row=1, column=0, padx=20, pady=10)
# Button Vermögen
self.sidebar_button_2 = customtkinter.CTkButton(self.sidebar_frame, text="Vermögen", command=self.sidebar_button_event)
self.sidebar_button_2.grid(row=2, column=0, padx=20, pady=10)
# Button Projekte
self.sidebar_button_3 = customtkinter.CTkButton(self.sidebar_frame, text="Projekte", command=self.sidebar_button_event)
self.sidebar_button_3.grid(row=3, column=0, padx=20, pady=10)
# Button Kategorien
self.sidebar_button_4 = customtkinter.CTkButton(self.sidebar_frame, text="Kategorien", command=self.sidebar_button_event)
self.sidebar_button_4.grid(row=4, column=0, padx=20, pady=10)
# Button Einträge
self.sidebar_button_4 = customtkinter.CTkButton(self.sidebar_frame, text="Einträge", command=self.sidebar_button_event)
self.sidebar_button_4.grid(row=6, column=0, padx=20, pady=10)
# Button Übersicht
self.sidebar_button_5 = customtkinter.CTkButton(self.sidebar_frame, text="Übersicht", command=self.sidebar_button_event)
self.sidebar_button_5.grid(row=7, column=0, padx=20, pady=10)
# Button Export
self.sidebar_button_6 = customtkinter.CTkButton(self.sidebar_frame, text="Export", command=self.sidebar_button_event)
self.sidebar_button_6.grid(row=8, column=0, padx=20, pady=10)
# Apperance Mode Label
self.appearance_mode_label = customtkinter.CTkLabel(self.sidebar_frame, text="Appearance Mode:", anchor="w")
self.appearance_mode_label.grid(row=10, column=0, padx=20, pady=(10, 0))
# Apperance Mode Option Menu
self.appearance_mode_optionemenu = customtkinter.CTkOptionMenu(self.sidebar_frame, values=["System", "Dark", "Light"],
command=self.change_appearance_mode_event)
self.appearance_mode_optionemenu.grid(row=11, column=0, padx=20, pady=(10, 10))
# UI Scaling Label
self.scaling_label = customtkinter.CTkLabel(self.sidebar_frame, text="UI Scaling:", anchor="w")
self.scaling_label.grid(row=12, column=0, padx=20, pady=(10, 0))
# UI Scaling Option Menu
self.scaling_optionemenu = customtkinter.CTkOptionMenu(self.sidebar_frame, values=["80%", "90%", "100%", "110%", "120%"],
command=self.change_scaling_event)
self.scaling_optionemenu.grid(row=13, column=0, padx=20, pady=(10, 20))
#Events
def change_appearance_mode_event(self, new_appearance_mode: str): def change_appearance_mode_event(self, new_appearance_mode: str):
customtkinter.set_appearance_mode(new_appearance_mode) customtkinter.set_appearance_mode(new_appearance_mode)
@ -76,7 +35,6 @@ class App(customtkinter.CTk):
def sidebar_button_event(self): def sidebar_button_event(self):
print("sidebar_button click") print("sidebar_button click")
if __name__ == "__main__": if __name__ == "__main__":
app = App() app = App()
app.mainloop() app.mainloop()

0
elements/__init__.py

52
elements/sidebar.py

@ -0,0 +1,52 @@
import tkinter
import tkinter.messagebox
import customtkinter
# create sidebar frame with widgets
def sidebar(self):
self.sidebar_frame = customtkinter.CTkFrame(self, width=140, corner_radius=0)
self.sidebar_frame.grid(row=0, column=0, rowspan=4, sticky="nsew")
self.sidebar_frame.grid_rowconfigure(9, weight=1)
# Logo
self.logo_label = customtkinter.CTkLabel(self.sidebar_frame, text="BudgetPy", font=customtkinter.CTkFont(size=20, weight="bold"))
self.logo_label.grid(row=0, column=0, padx=20, pady=(20, 10))
# Button Personen
self.sidebar_button_1 = customtkinter.CTkButton(self.sidebar_frame, text="Personen", command=self.sidebar_button_event)
self.sidebar_button_1.grid(row=1, column=0, padx=20, pady=10)
# Button Vermögen
self.sidebar_button_2 = customtkinter.CTkButton(self.sidebar_frame, text="Vermögen", command=self.sidebar_button_event)
self.sidebar_button_2.grid(row=2, column=0, padx=20, pady=10)
# Button Projekte
self.sidebar_button_3 = customtkinter.CTkButton(self.sidebar_frame, text="Projekte", command=self.sidebar_button_event)
self.sidebar_button_3.grid(row=3, column=0, padx=20, pady=10)
# Button Kategorien
self.sidebar_button_4 = customtkinter.CTkButton(self.sidebar_frame, text="Kategorien", command=self.sidebar_button_event)
self.sidebar_button_4.grid(row=4, column=0, padx=20, pady=10)
# Button Einträge
self.sidebar_button_4 = customtkinter.CTkButton(self.sidebar_frame, text="Einträge", command=self.sidebar_button_event)
self.sidebar_button_4.grid(row=6, column=0, padx=20, pady=10)
# Button Übersicht
self.sidebar_button_5 = customtkinter.CTkButton(self.sidebar_frame, text="Übersicht", command=self.sidebar_button_event)
self.sidebar_button_5.grid(row=7, column=0, padx=20, pady=10)
# Button Export
self.sidebar_button_6 = customtkinter.CTkButton(self.sidebar_frame, text="Export", command=self.sidebar_button_event)
self.sidebar_button_6.grid(row=8, column=0, padx=20, pady=10)
# Apperance Mode Label
self.appearance_mode_label = customtkinter.CTkLabel(self.sidebar_frame, text="Appearance Mode:", anchor="w")
self.appearance_mode_label.grid(row=10, column=0, padx=20, pady=(10, 0))
# Apperance Mode Option Menu
self.appearance_mode_optionemenu = customtkinter.CTkOptionMenu(self.sidebar_frame, values=["System", "Dark", "Light"],
command=self.change_appearance_mode_event)
self.appearance_mode_optionemenu.grid(row=11, column=0, padx=20, pady=(10, 10))
# UI Scaling Label
self.scaling_label = customtkinter.CTkLabel(self.sidebar_frame, text="UI Scaling:", anchor="w")
self.scaling_label.grid(row=12, column=0, padx=20, pady=(10, 0))
# UI Scaling Option Menu
self.scaling_optionemenu = customtkinter.CTkOptionMenu(self.sidebar_frame, values=["80%", "90%", "100%", "110%", "120%"],
command=self.change_scaling_event)
self.scaling_optionemenu.grid(row=13, column=0, padx=20, pady=(10, 20))
Loading…
Cancel
Save