import tkinter as tk
from tkinter import ttk
class SettingsApp(tk.Tk):
def __init__(self):
super().__init__()
# Configure the main window
self.title("Application Settings (LabelFrame Demo)")
self.geometry("600x400")
self.configure(bg='#f0f0f0')
# Create the main container with padding
main_container = ttk.Frame(self, padding="20")
main_container.pack(fill=tk.BOTH, expand=True)
# Create and pack the personal info section
self.create_personal_info_frame(main_container)
# Create and pack the preferences section
self.create_preferences_frame(main_container)
# Create and pack the notification settings
self.create_notification_frame(main_container)
def create_personal_info_frame(self, parent: ttk.Frame) -> None:
"""Creates a LabelFrame for personal information settings."""
personal_frame = ttk.LabelFrame(
parent,
text="Personal Information",
padding="10"
)
personal_frame.pack(fill=tk.X, pady=(0, 10))
# Create and pack the form elements
ttk.Label(personal_frame, text="Name:").grid(row=0, column=0, sticky=tk.W, pady=5)
ttk.Entry(personal_frame).grid(row=0, column=1, sticky=tk.EW, padx=(10, 0))
ttk.Label(personal_frame, text="Email:").grid(row=1, column=0, sticky=tk.W, pady=5)
ttk.Entry(personal_frame).grid(row=1, column=1, sticky=tk.EW, padx=(10, 0))
# Configure grid column weights
personal_frame.columnconfigure(1, weight=1)
def create_preferences_frame(self, parent: ttk.Frame) -> None:
"""Creates a LabelFrame for application preferences."""
pref_frame = ttk.LabelFrame(
parent,
text="Application Preferences",
padding="10"
)
pref_frame.pack(fill=tk.X, pady=(0, 10))
# Theme selection
ttk.Label(pref_frame, text="Theme:").grid(row=0, column=0, sticky=tk.W, pady=5)
theme_combo = ttk.Combobox(
pref_frame,
values=["Light", "Dark", "System"],
state="readonly"
)
theme_combo.set("Light")
theme_combo.grid(row=0, column=1, sticky=tk.EW, padx=(10, 0))
# Language selection
ttk.Label(pref_frame, text="Language:").grid(row=1, column=0, sticky=tk.W, pady=5)
lang_combo = ttk.Combobox(
pref_frame,
values=["English", "Spanish", "French", "German"],
state="readonly"
)
lang_combo.set("English")
lang_combo.grid(row=1, column=1, sticky=tk.EW, padx=(10, 0))
# Configure grid column weights
pref_frame.columnconfigure(1, weight=1)
def create_notification_frame(self, parent: ttk.Frame) -> None:
"""Creates a LabelFrame for notification settings."""
notif_frame = ttk.LabelFrame(
parent,
text="Notification Settings",
padding="10"
)
notif_frame.pack(fill=tk.X)
# Email notifications
ttk.Checkbutton(
notif_frame,
text="Enable email notifications"
).grid(row=0, column=0, sticky=tk.W, pady=2)
# Desktop notifications
ttk.Checkbutton(
notif_frame,
text="Enable desktop notifications"
).grid(row=1, column=0, sticky=tk.W, pady=2)
# Sound notifications
ttk.Checkbutton(
notif_frame,
text="Enable sound notifications"
).grid(row=2, column=0, sticky=tk.W, pady=2)
if __name__ == "__main__":
app = SettingsApp()
app.mainloop()