├── preview.png ├── CTkFloatingNotifications ├── __init__.py ├── notification_type.py ├── notification_manager.py └── notification_panel.py ├── example.py └── README.md /preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxverwiebe/CTkFloatingNotifications/HEAD/preview.png -------------------------------------------------------------------------------- /CTkFloatingNotifications/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0" 2 | 3 | from .notification_manager import * 4 | from .notification_type import * 5 | from .notification_panel import * 6 | -------------------------------------------------------------------------------- /CTkFloatingNotifications/notification_type.py: -------------------------------------------------------------------------------- 1 | from enum import Enum 2 | 3 | class NotifyType(Enum): 4 | INFO = ("#00bfff") # Dark gray with blue line 5 | SUCCESS = ("#28a745") # Dark gray with green line 6 | WARNING = ("#ffc107") # Dark gray with orange line 7 | ERROR = ("#dc3545") # Dark gray with red line 8 | 9 | def __init__(self, line_color): 10 | self.line_color = line_color -------------------------------------------------------------------------------- /CTkFloatingNotifications/notification_manager.py: -------------------------------------------------------------------------------- 1 | from .notification_panel import NotificationPanel 2 | from .notification_type import NotifyType 3 | 4 | class NotificationManager: 5 | def __init__(self, master): 6 | self.master = master 7 | self.notifications = [] 8 | 9 | def show_notification(self, message, notify_type=NotifyType.INFO, duration=5000, bg_color="#dbdbdb", text_color="#262626"): 10 | NotificationPanel(self.master, self, message, notify_type=notify_type, duration=duration, bg_color=bg_color, text_color=text_color) 11 | 12 | def add_notification(self, notification): 13 | self.notifications.append(notification) 14 | self.update_notification_positions() 15 | 16 | def remove_notification(self, notification): 17 | if notification in self.notifications: 18 | self.notifications.remove(notification) 19 | self.update_notification_positions() 20 | 21 | def update_notification_positions(self): 22 | for index, notification in enumerate(self.notifications): 23 | y_offset = -20 - (index * 70) # Adjust height as necessary 24 | notification.place(relx=1.0, rely=1.0, x=-20, y=y_offset, anchor="se") -------------------------------------------------------------------------------- /CTkFloatingNotifications/notification_panel.py: -------------------------------------------------------------------------------- 1 | import customtkinter as ctk 2 | import tkinter as tk 3 | from .notification_type import NotifyType 4 | 5 | class NotificationPanel(ctk.CTkFrame): 6 | def __init__(self, master, manager, message, notify_type=NotifyType.INFO, duration=5000, bg_color="#dbdbdb", text_color="#262626"): 7 | text_length = len(message) 8 | width = max(250, min(600, text_length * 7)) 9 | height = 50 10 | 11 | super().__init__(master, corner_radius=0, fg_color=bg_color, width=width, height=height) 12 | self.pack_propagate(False) 13 | self.duration = duration 14 | self.manager = manager 15 | 16 | self.line_frame = ctk.CTkFrame(self, width=5, height=height, fg_color=notify_type.line_color) 17 | self.line_frame.place(relx=0, rely=0, anchor="nw") 18 | 19 | self.label = ctk.CTkLabel(self, text=message, text_color=text_color, anchor="w", font=("Arial", 12), justify="left", wraplength=width - 50) 20 | self.label.pack(pady=5, padx=(15, 10), fill="both", expand=True) 21 | 22 | self.close_button = ctk.CTkButton(self, text="✖", width=15, height=15, command=self.remove_notification, fg_color="transparent", hover_color=bg_color, text_color=text_color, corner_radius=10) 23 | self.close_button.place(relx=0.98, rely=0.1, anchor="ne") 24 | 25 | self.manager.add_notification(self) 26 | 27 | self.after(duration, self.remove_notification) 28 | 29 | def remove_notification(self): 30 | self.manager.remove_notification(self) 31 | self.destroy() 32 | -------------------------------------------------------------------------------- /example.py: -------------------------------------------------------------------------------- 1 | import customtkinter as ctk 2 | from CTkFloatingNotifications import NotificationManager, NotifyType 3 | 4 | class Example(ctk.CTk): 5 | def __init__(self): 6 | super().__init__() 7 | self.geometry("400x300") 8 | self.title("Notification Example") 9 | self.notification_manager = NotificationManager(self) 10 | 11 | self.notify_button_info = ctk.CTkButton(self, text="Show Info", command=lambda: self.notification_manager.show_notification("This is an info notification!", NotifyType.INFO), fg_color="#00bfff", hover_color="#009acd") 12 | self.notify_button_info.pack(pady=10) 13 | 14 | self.notify_button_success = ctk.CTkButton(self, text="Show Success", command=lambda: self.notification_manager.show_notification("This is a success notification!", NotifyType.SUCCESS), fg_color="#28a745", hover_color="#218838") 15 | self.notify_button_success.pack(pady=10) 16 | 17 | self.notify_button_warning = ctk.CTkButton(self, text="Show Warning", command=lambda: self.notification_manager.show_notification("This is a warning notification!", NotifyType.WARNING), fg_color="#ffc107", hover_color="#e0a800") 18 | self.notify_button_warning.pack(pady=10) 19 | 20 | self.notify_button_error = ctk.CTkButton(self, text="Show Error", command=lambda: self.notification_manager.show_notification("This is an error notification!", NotifyType.ERROR), fg_color="#dc3545", hover_color="#c82333") 21 | self.notify_button_error.pack(pady=10) 22 | 23 | self.notify_button_error_dark = ctk.CTkButton(self, text="Show Error Dark", command=lambda: self.notification_manager.show_notification("This is an error notification!", NotifyType.ERROR, bg_color="#292929", text_color="#b0b0b0"), fg_color="#dc3545", hover_color="#c82333") 24 | self.notify_button_error_dark.pack(pady=10) 25 | 26 | if __name__ == "__main__": 27 | app = Example() 28 | app.mainloop() 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CTkFloatingNotifications 2 | 3 | CTkFloatingNotifications is a custom notification manager widget built using the CustomTkinter library. It provides an easy way to display various types of notifications within a CustomTkinter application, enhancing user experience with visual alerts. 4 | 5 | ![alt text](https://github.com/maxverwiebe/CTkFloatingNotifications/blob/main/preview.png?raw=true) 6 | 7 | ## Features 8 | 9 | - **Information Notifications**: Display informational messages to the user. 10 | - **Success Notifications**: Indicate successful operations. 11 | - **Warning Notifications**: Alert users about potential issues. 12 | - **Error Notifications**: Notify users about errors. 13 | - **Dark Mode**: Display notifications with a dark background for better visibility in dark-themed applications. 14 | 15 | ## Installation 16 | 17 | To use CTkFloatingNotifications, you need to have CustomTkinter and CTkFloatingNotifications installed. 18 | ```bash 19 | pip install customtkinter 20 | ``` 21 | 22 | And clone this repo. 23 | 24 | ## Usage 25 | 26 | ### Basic Example 27 | 28 | Here's a basic example of how to use CTkFloatingNotifications in your application: 29 | 30 | ```python 31 | import customtkinter as ctk 32 | from CTkFloatingNotifications import NotificationManager, NotifyType 33 | 34 | class Example(ctk.CTk): 35 | def __init__(self): 36 | super().__init__() 37 | self.geometry("400x300") 38 | self.title("Notification Example") 39 | self.notification_manager = NotificationManager(self) 40 | 41 | self.notify_button_info = ctk.CTkButton(self, text="Show Info", command=lambda: self.notification_manager.show_notification("This is an info notification!", NotifyType.INFO), fg_color="#00bfff", hover_color="#009acd") 42 | self.notify_button_info.pack(pady=10) 43 | 44 | self.notify_button_success = ctk.CTkButton(self, text="Show Success", command=lambda: self.notification_manager.show_notification("This is a success notification!", NotifyType.SUCCESS), fg_color="#28a745", hover_color="#218838") 45 | self.notify_button_success.pack(pady=10) 46 | 47 | self.notify_button_warning = ctk.CTkButton(self, text="Show Warning", command=lambda: self.notification_manager.show_notification("This is a warning notification!", NotifyType.WARNING), fg_color="#ffc107", hover_color="#e0a800") 48 | self.notify_button_warning.pack(pady=10) 49 | 50 | self.notify_button_error = ctk.CTkButton(self, text="Show Error", command=lambda: self.notification_manager.show_notification("This is an error notification!", NotifyType.ERROR), fg_color="#dc3545", hover_color="#c82333") 51 | self.notify_button_error.pack(pady=10) 52 | 53 | self.notify_button_error_dark = ctk.CTkButton(self, text="Show Error Dark", command=lambda: self.notification_manager.show_notification("This is an error notification!", NotifyType.ERROR, bg_color="#292929", text_color="#b0b0b0"), fg_color="#dc3545", hover_color="#c82333") 54 | self.notify_button_error_dark.pack(pady=10) 55 | 56 | if __name__ == "__main__": 57 | app = Example() 58 | app.mainloop() 59 | ``` 60 | 61 | ### Customization 62 | 63 | - **Notification Colors**: Customize the foreground and hover colors for buttons to match your application's theme. 64 | - **Dark Mode**: Use `bg_color` and `text_color` parameters to create dark-themed notifications. 65 | - **Notification Duration**: Adjust the duration for which the notification is displayed using the `duration` parameter. 66 | 67 | #### Example: 68 | 69 | ```python 70 | self.notification_manager.show_notification( 71 | "This is a custom notification!", 72 | notify_type=NotifyType.INFO, 73 | duration=7000, # Display for 7 seconds 74 | bg_color="#dbdbdb", # Custom background color 75 | text_color="#262626" # Custom text color 76 | ) 77 | ``` 78 | 79 | ## Methods 80 | 81 | ### `show_notification(message, notify_type, bg_color=None, text_color=None)` 82 | 83 | - **Description**: Display a notification with the specified message and type. 84 | - **Parameters**: 85 | - `message` (str): The message to display in the notification. 86 | - `notify_type` (NotifyType): The type of notification (INFO, SUCCESS, WARNING, ERROR). 87 | - `bg_color` (str, optional): Background color of the notification. 88 | - `text_color` (str, optional): Text color of the notification. 89 | 90 | ### Notification Types 91 | 92 | - `NotifyType.INFO`: For informational messages. 93 | - `NotifyType.SUCCESS`: For success messages. 94 | - `NotifyType.WARNING`: For warning messages. 95 | - `NotifyType.ERROR`: For error messages. 96 | 97 | ## Contributing 98 | 99 | Contributions are welcome! Please fork the repository and submit a pull request with your improvements. 100 | 101 | ## License 102 | 103 | This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. 104 | 105 | ## Acknowledgments 106 | 107 | - [CustomTkinter](https://github.com/TomSchimansky/CustomTkinter) for providing a great framework for creating modern and customizable GUI applications in Python. 108 | 109 | Feel free to customize this README to better suit your project's specific details and needs! 110 | --------------------------------------------------------------------------------