CTkCollapsiblePanel is a custom collapsible panel widget built on top of CustomTkinter. It provides a collapsible area to neatly show or hide content on demand, making your GUI more organized and space-efficient.
- Collapsible Content Area: Users can toggle the visibility of the panel’s content by clicking a header button.
- Theme Compatibility: Adapts to CustomTkinter’s appearance settings (colors, fonts, modes).
- Easy Content Addition: Add any widgets (labels, buttons, entries, etc.) to the
_content_frame
. - Minimalistic API: Simple integration into your existing CustomTkinter applications.
Make sure CustomTkinter is installed:
pip install customtkinter
Then, simply add CTkCollapsiblePanel.py
to your project or copy the class code into your own file.
import customtkinter as ctk
from CTkCollapsiblePanel import *
if __name__ == "__main__":
ctk.set_appearance_mode("System") # "System", "Dark", or "Light"
app = ctk.CTk()
app.title("Collapsible Panel Example")
# Create a panel
panel1 = CTkCollapsiblePanel(app, title="Panel 1")
panel1.pack(fill="x", pady=10, padx=10)
# Add content to the panel
label = ctk.CTkLabel(panel1._content_frame, text="Content of Panel 1", anchor="w")
label.pack(fill="x", padx=10, pady=5)
app.mainloop()
To add more widgets, simply place them into panel._content_frame
:
panel2 = CTkCollapsiblePanel(app, title="Panel 2")
panel2.pack(fill="x", pady=10, padx=10)
extra_label = ctk.CTkLabel(panel2._content_frame, text="More content in Panel 2", anchor="w")
extra_label.pack(fill="x", padx=10, pady=5)
- Description: Toggles the panel’s content visibility.
- Usage: Automatically called when the header button is clicked, but can also be called manually if needed.
- Description: Contains the widgets displayed within the panel.
- Access:
panel = CTkCollapsiblePanel(app, title="Panel") # Add widgets inside the panel’s content frame panel._content_frame
- Title: Set the panel’s title via the
title
parameter in the constructor. - Styles and Colors: Since the panel inherits from
CTkFrame
and usesCTkButton
, it will follow the theme settings from CustomTkinter. You can further customize colors, fonts, and other properties via theconfigure
methods of the internal widgets.
For example, adjusting the font:
panel1.header_button.configure(font=("Arial", 16, "italic"))
This project is licensed under the MIT License.
- CustomTkinter for providing a great framework for creating modern and customizable GUI applications in Python.