From 528f5e7a20b65c85c1119c3b825b8bc80ab27b33 Mon Sep 17 00:00:00 2001 From: SHAHZAIN ALI Date: Wed, 27 Dec 2023 19:38:17 +0500 Subject: [PATCH 1/4] created an alert dialog using input dialog --- customtkinter/windows/ctk_alert_dialog.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 customtkinter/windows/ctk_alert_dialog.py diff --git a/customtkinter/windows/ctk_alert_dialog.py b/customtkinter/windows/ctk_alert_dialog.py new file mode 100644 index 00000000..e69de29b From 7bad61d7a04ef1ea24fc46345c9a5c7115801d5d Mon Sep 17 00:00:00 2001 From: SHAHZAIN ALI Date: Wed, 27 Dec 2023 19:40:21 +0500 Subject: [PATCH 2/4] created an alert dialog using input dialog --- customtkinter/windows/ctk_alert_dialog.py | 95 +++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/customtkinter/windows/ctk_alert_dialog.py b/customtkinter/windows/ctk_alert_dialog.py index e69de29b..f72d7888 100644 --- a/customtkinter/windows/ctk_alert_dialog.py +++ b/customtkinter/windows/ctk_alert_dialog.py @@ -0,0 +1,95 @@ +from typing import Union, Tuple, Optional + +from .widgets import CTkLabel +from .widgets import CTkEntry +from .widgets import CTkButton +from .widgets.theme import ThemeManager +from .ctk_toplevel import CTkToplevel +from .widgets.font import CTkFont + + +class CTkInputDialog(CTkToplevel): + """ + Dialog with extra window, message, entry widget, cancel and ok button. + For detailed information check out the documentation. + """ + + def __init__(self, + fg_color: Optional[Union[str, Tuple[str, str]]] = None, + text_color: Optional[Union[str, Tuple[str, str]]] = None, + button_fg_color: Optional[Union[str, Tuple[str, str]]] = None, + button_hover_color: Optional[Union[str, Tuple[str, str]]] = None, + button_text_color: Optional[Union[str, Tuple[str, str]]] = None, + title: str = "CTkDialog", + font: Optional[Union[tuple, CTkFont]] = None, + text: str = "CTkDialog"): + + super().__init__(fg_color=fg_color) + + self._fg_color = ThemeManager.theme["CTkToplevel"]["fg_color"] if fg_color is None else self._check_color_type(fg_color) + self._text_color = ThemeManager.theme["CTkLabel"]["text_color"] if text_color is None else self._check_color_type(button_hover_color) + self._button_fg_color = ThemeManager.theme["CTkButton"]["fg_color"] if button_fg_color is None else self._check_color_type(button_fg_color) + self._button_hover_color = ThemeManager.theme["CTkButton"]["hover_color"] if button_hover_color is None else self._check_color_type(button_hover_color) + self._button_text_color = ThemeManager.theme["CTkButton"]["text_color"] if button_text_color is None else self._check_color_type(button_text_color) + self._running: bool = False + self._title = title + self._text = text + self._font = font + + self.title(self._title) + self.lift() # lift window on top + self.attributes("-topmost", True) # stay on top + self.protocol("WM_DELETE_WINDOW", self._on_closing) + self.after(10, self._create_widgets) # create widgets with slight delay, to avoid white flickering of background + self.resizable(False, False) + self.grab_set() # make other windows not clickable + + def _create_widgets(self): + self.grid_columnconfigure((0, 1), weight=1) + self.rowconfigure(0, weight=1) + + self._label = CTkLabel(master=self, + width=300, + wraplength=300, + fg_color="transparent", + text_color=self._text_color, + text=self._text, + font=self._font) + self._label.grid(row=0, column=0, columnspan=2, padx=20, pady=20, sticky="ew") + + self._ok_button = CTkButton(master=self, + width=100, + border_width=0, + fg_color=self._button_fg_color, + hover_color=self._button_hover_color, + text_color=self._button_text_color, + text='Ok', + font=self._font, + command=self._ok_event) + self._ok_button.grid(row=2, column=0, columnspan=1, padx=(20, 10), pady=(0, 20), sticky="ew") + + self._cancel_button = CTkButton(master=self, + width=100, + border_width=0, + fg_color=self._button_fg_color, + hover_color=self._button_hover_color, + text_color=self._button_text_color, + text='Cancel', + font=self._font, + command=self._cancel_event) + self._cancel_button.grid(row=2, column=1, columnspan=1, padx=(10, 20), pady=(0, 20), sticky="ew") + + + def _ok_event(self, event=None): + self._user_input = self._entry.get() + self.grab_release() + self.destroy() + + def _on_closing(self): + self.grab_release() + self.destroy() + + def _cancel_event(self): + self.grab_release() + self.destroy() + From dd531aa9158e0a4f811fd75992d60a323d6ff8c7 Mon Sep 17 00:00:00 2001 From: SHAHZAIN ALI Date: Wed, 27 Dec 2023 19:49:02 +0500 Subject: [PATCH 3/4] created an alert dialog using input dialog, use get_state for getting onPositive or onNegative either True or False --- customtkinter/windows/ctk_alert_dialog.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/customtkinter/windows/ctk_alert_dialog.py b/customtkinter/windows/ctk_alert_dialog.py index f72d7888..db668730 100644 --- a/customtkinter/windows/ctk_alert_dialog.py +++ b/customtkinter/windows/ctk_alert_dialog.py @@ -1,16 +1,15 @@ from typing import Union, Tuple, Optional from .widgets import CTkLabel -from .widgets import CTkEntry from .widgets import CTkButton from .widgets.theme import ThemeManager from .ctk_toplevel import CTkToplevel from .widgets.font import CTkFont -class CTkInputDialog(CTkToplevel): +class CTkAlertDialog(CTkToplevel): """ - Dialog with extra window, message, entry widget, cancel and ok button. + Dialog with extra window, message, cancel and ok button. For detailed information check out the documentation. """ @@ -31,6 +30,7 @@ def __init__(self, self._button_fg_color = ThemeManager.theme["CTkButton"]["fg_color"] if button_fg_color is None else self._check_color_type(button_fg_color) self._button_hover_color = ThemeManager.theme["CTkButton"]["hover_color"] if button_hover_color is None else self._check_color_type(button_hover_color) self._button_text_color = ThemeManager.theme["CTkButton"]["text_color"] if button_text_color is None else self._check_color_type(button_text_color) + self._is_ok: bool = False self._running: bool = False self._title = title self._text = text @@ -81,7 +81,7 @@ def _create_widgets(self): def _ok_event(self, event=None): - self._user_input = self._entry.get() + self._is_ok = True self.grab_release() self.destroy() @@ -90,6 +90,11 @@ def _on_closing(self): self.destroy() def _cancel_event(self): + self._is_ok = False self.grab_release() self.destroy() + def get_state(self): + self.master.wait_window(self) + return self._is_ok + From 4499ffc116665272bed93d34c96d49b1397dc9e2 Mon Sep 17 00:00:00 2001 From: SHAHZAIN ALI Date: Wed, 27 Dec 2023 20:20:29 +0500 Subject: [PATCH 4/4] added imports in init --- customtkinter/__init__.py | 1 + customtkinter/windows/__init__.py | 1 + 2 files changed, 2 insertions(+) diff --git a/customtkinter/__init__.py b/customtkinter/__init__.py index ac1a8b70..a2cd1519 100644 --- a/customtkinter/__init__.py +++ b/customtkinter/__init__.py @@ -39,6 +39,7 @@ from .windows import CTk from .windows import CTkToplevel from .windows import CTkInputDialog +from .windows import CTkAlertDialog # import font classes from .windows.widgets.font import CTkFont diff --git a/customtkinter/windows/__init__.py b/customtkinter/windows/__init__.py index ca681b72..050ca9fe 100644 --- a/customtkinter/windows/__init__.py +++ b/customtkinter/windows/__init__.py @@ -1,3 +1,4 @@ from .ctk_tk import CTk from .ctk_toplevel import CTkToplevel from .ctk_input_dialog import CTkInputDialog +from .ctk_alert_dialog import CTkAlertDialog