First version

This commit is contained in:
PolRubio 2023-08-10 18:40:04 +02:00
parent 1430fb397a
commit f25bbcee74

View File

@ -3,9 +3,9 @@ from typing import Union, Tuple, Optional
from .widgets import CTkLabel from .widgets import CTkLabel
from .widgets import CTkEntry from .widgets import CTkEntry
from .widgets import CTkButton from .widgets import CTkButton
from .widgets import CTkComboBox
from .widgets.theme import ThemeManager from .widgets.theme import ThemeManager
from .ctk_toplevel import CTkToplevel from .ctk_toplevel import CTkToplevel
from .widgets.font import CTkFont
class CTkInputDialog(CTkToplevel): class CTkInputDialog(CTkToplevel):
@ -23,9 +23,8 @@ class CTkInputDialog(CTkToplevel):
entry_fg_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_border_color: Optional[Union[str, Tuple[str, str]]] = None,
entry_text_color: Optional[Union[str, Tuple[str, str]]] = None, entry_text_color: Optional[Union[str, Tuple[str, str]]] = None,
values: Optional[Union[str, list[str]]] = None,
title: str = "CTkDialog", title: str = "CTkDialog",
font: Optional[Union[tuple, CTkFont]] = None,
text: str = "CTkDialog"): text: str = "CTkDialog"):
super().__init__(fg_color=fg_color) super().__init__(fg_color=fg_color)
@ -41,11 +40,11 @@ class CTkInputDialog(CTkToplevel):
self._user_input: Union[str, None] = None self._user_input: Union[str, None] = None
self._running: bool = False self._running: bool = False
self._title = title
self._text = text self._text = text
self._font = font
self._values = values
self.title(self._title) self.title(title)
self.lift() # lift window on top self.lift() # lift window on top
self.attributes("-topmost", True) # stay on top self.attributes("-topmost", True) # stay on top
self.protocol("WM_DELETE_WINDOW", self._on_closing) self.protocol("WM_DELETE_WINDOW", self._on_closing)
@ -54,6 +53,7 @@ class CTkInputDialog(CTkToplevel):
self.grab_set() # make other windows not clickable self.grab_set() # make other windows not clickable
def _create_widgets(self): def _create_widgets(self):
self.grid_columnconfigure((0, 1), weight=1) self.grid_columnconfigure((0, 1), weight=1)
self.rowconfigure(0, weight=1) self.rowconfigure(0, weight=1)
@ -62,16 +62,22 @@ class CTkInputDialog(CTkToplevel):
wraplength=300, wraplength=300,
fg_color="transparent", fg_color="transparent",
text_color=self._text_color, text_color=self._text_color,
text=self._text, text=self._text,)
font=self._font)
self._label.grid(row=0, column=0, columnspan=2, padx=20, pady=20, sticky="ew") self._label.grid(row=0, column=0, columnspan=2, padx=20, pady=20, sticky="ew")
self._entry = CTkEntry(master=self, if self._values is not None:
width=230, self._entry = CTkComboBox(master=self,
fg_color=self._entry_fg_color, width=230,
border_color=self._entry_border_color, fg_color=self._entry_fg_color,
text_color=self._entry_text_color, border_color=self._entry_border_color,
font=self._font) text_color=self._entry_text_color,
values=self._values)
else:
self._entry = CTkEntry(master=self,
width=230,
fg_color=self._entry_fg_color,
border_color=self._entry_border_color,
text_color=self._entry_text_color)
self._entry.grid(row=1, column=0, columnspan=2, padx=20, pady=(0, 20), sticky="ew") self._entry.grid(row=1, column=0, columnspan=2, padx=20, pady=(0, 20), sticky="ew")
self._ok_button = CTkButton(master=self, self._ok_button = CTkButton(master=self,
@ -81,7 +87,6 @@ class CTkInputDialog(CTkToplevel):
hover_color=self._button_hover_color, hover_color=self._button_hover_color,
text_color=self._button_text_color, text_color=self._button_text_color,
text='Ok', text='Ok',
font=self._font,
command=self._ok_event) command=self._ok_event)
self._ok_button.grid(row=2, column=0, columnspan=1, padx=(20, 10), pady=(0, 20), sticky="ew") self._ok_button.grid(row=2, column=0, columnspan=1, padx=(20, 10), pady=(0, 20), sticky="ew")
@ -92,7 +97,6 @@ class CTkInputDialog(CTkToplevel):
hover_color=self._button_hover_color, hover_color=self._button_hover_color,
text_color=self._button_text_color, text_color=self._button_text_color,
text='Cancel', text='Cancel',
font=self._font,
command=self._cancel_event) command=self._cancel_event)
self._cancel_button.grid(row=2, column=1, columnspan=1, padx=(10, 20), pady=(0, 20), sticky="ew") self._cancel_button.grid(row=2, column=1, columnspan=1, padx=(10, 20), pady=(0, 20), sticky="ew")