Added few comments and slightly improved example

This commit is contained in:
tardy-ish 2023-02-09 15:04:31 +05:30
parent a97c1a8720
commit a4aeb8f1a2
2 changed files with 30 additions and 16 deletions

View File

@ -8,22 +8,27 @@ from .ctk_toplevel import CTkToplevel
class CTkConfirmationBox(CTkToplevel): class CTkConfirmationBox(CTkToplevel):
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,
entry_fg_color: Optional[Union[str, Tuple[str, str]]] = None,
entry_border_color: Optional[Union[str, Tuple[str, str]]] = None,
entry_text_color: Optional[Union[str, Tuple[str, str]]] = None,
title: str = "CTkConfirmationBox", """
yes: callable= lambda: print("Pressed Yes"), Dialog box meant for a simple "are you sure"/confirmation
no: callable = lambda: print("Pressed No") For either events yes or no, functions can be passed
): during the creation of the widget
# def __init__(self,__yes__,__no__ = lambda: print("Pressed No"), *args, **kwargs): By default on closing the no function gets executed
# super().__init__(*args, **kwargs) """
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,
entry_fg_color: Optional[Union[str, Tuple[str, str]]] = None,
entry_border_color: Optional[Union[str, Tuple[str, str]]] = None,
entry_text_color: Optional[Union[str, Tuple[str, str]]] = None,
title: str = "CTkConfirmationBox",
yes: callable = lambda: print("Pressed Yes"),
no: callable = lambda: print("Pressed No")
):
super().__init__(fg_color=fg_color) super().__init__(fg_color=fg_color)

View File

@ -7,8 +7,17 @@ app = ctk.CTk()
app.geometry("400x300") app.geometry("400x300")
def open_box(): def open_box():
ctk.CTkConfirmationBox() ctk.CTkConfirmationBox(yes=_yes_event,no=_no_event)
def _yes_event():
print("This is when the yes button gets pressed")
def _no_event():
print("This is when the no button gets pressed")
button = ctk.CTkButton(master=app,text="open confirmation box",command=open_box) button = ctk.CTkButton(master=app,text="open confirmation box",command=open_box)
button.place(relx=0.5, rely=0.5, anchor=tk.CENTER) button.place(relx=0.5, rely=0.5, anchor=tk.CENTER)