import tkinter as tk
from tkinter import ttk
class Dashboard:
def __init__(self, title):
[Link] = [Link]()
[Link](title)
def open_maximised(self):
[Link]('zoomed')
def close(self):
[Link]()
class WidgetFactory:
def new_frame(self, parent, bg, borderwidth, width=None):
frame = [Link](parent, bg=bg, bd=borderwidth, width=width)
return frame
def new_button(self, parent, text, command, bg="#121212", width=200, height=50,
borderwidth=5, hover=None, focus=None):
button = [Link](parent, text=text, command=command, bg=bg, width=width,
height=height)
return button
def new_label(self, parent, text, bg="#121212"):
label = [Link](parent, text=text, bg=bg)
return label
def new_input(self, parent, bg="#323232"):
entry = [Link](parent, bg=bg)
return entry
def clear_widget(self, widget):
for child in widget.winfo_children():
[Link]()
def close_window(window):
return lambda: [Link]()
def home_page(dashboard, widget, content):
home_container = widget.new_frame(content, "transparent", 5)
home_container.pack(expand=True, fill="both", padx=10, pady=10)
input_field = widget.new_input(home_container, "#323232")
input_field.pack(fill="x", pady=(12,0), padx=27, ipady=10)
def menu_page(dashboard, widget, content):
button = widget.new_button(content, "Close", close_window(dashboard))
[Link](expand=True)
def settings_page(dashboard, widget, content):
label = widget.new_label(content, "Settings")
[Link](expand=True)
def about_page(dashboard, widget, content):
label = widget.new_label(content, "About")
[Link](expand=True)
def set_button_focus(buttons, button_to_focus):
for button in buttons:
if button == button_to_focus:
[Link](relief="sunken")
else:
[Link](relief="raised")
def create_sidebar_button(widget, parent, text, buttons, content, width, height,
color, hover, focus, dashboard, click_function=None):
button = widget.new_button(
parent, text,
lambda: (
widget.clear_widget(content),
click_function(dashboard, widget, content) if click_function else None,
set_button_focus(buttons, button)
),
bg=color, width=width, height=height
)
button.pack_propagate(False)
[Link](side="top", fill="x")
return button
def dashboard_ui():
dashboard = Dashboard("Dashboard")
widget = WidgetFactory()
buttons = []
# Body element
body = widget.new_frame([Link], "#121212", 0)
[Link](expand=True, fill="both")
# Sidebar
sidebar = widget.new_frame(body, "transparent", 0, 200)
[Link](side="left", fill="y", padx=15, pady=10)
# Content element
main_container = widget.new_frame(body, "transparent", 0)
main_container.pack(
side="left", expand=True, fill="both", pady=(10, 10), padx=(0,10)
)
content = widget.new_frame(main_container, "#262626", 5)
[Link](expand=True, fill="both")
# List of menu items and corresponding functions
menu_items = [
("Home", home_page),
("Menu", menu_page),
("Settings", settings_page),
("About", about_page),
]
for label, function in menu_items:
button = create_sidebar_button(
widget, sidebar, label, buttons, content,
200, 50, "#121212", "#323232", "#2b2b2b",
dashboard, click_function=function
)
[Link](button)
# Focus the "Home" button
set_button_focus(buttons, buttons[0])
home_page(dashboard, widget, content)
dashboard.open_maximised()
[Link]()
if __name__ == '__main__':
dashboard_ui()