diff --git a/README.md b/README.md index 63f7b88..0bd57e3 100644 --- a/README.md +++ b/README.md @@ -58,11 +58,16 @@ Furthermore, a dialog is available that allows specifying multiple input fields. ```py import TkEasyGUI as eg -m = eg.popup_get_form(["Name", ["Age", "number"]]) +m = eg.popup_get_form([ + ("Name", "kujira"), + ("Age", 20, "number"), + ("Gender", ("M", "W", "-"))]) if m: name = m["Name"] age = m["Age"] - eg.print(f"name={name}, age={age}") # name=kujira, age=20.0 + gender = m["Gender"] + eg.print(f"name={name}, age={age}, gender={gender}") + # name=kujira, age=20.0, gender=M ``` - [Docs > Dialogs](https://github.com/kujirahand/tkeasygui-python/blob/main/docs/TkEasyGUI/dialogs-py.md) diff --git a/TkEasyGUI/dialogs.py b/TkEasyGUI/dialogs.py index 8fbdf10..0db5f20 100644 --- a/TkEasyGUI/dialogs.py +++ b/TkEasyGUI/dialogs.py @@ -595,7 +595,7 @@ def update_result(current_date): return result def popup_get_form( - form_items: list[Union[str, tuple[str, str], tuple[str, str, Any]]], # list of form items(label, type [, default]) + form_items: list[Union[str, tuple[str, Any], tuple[str, Any, str]]], # list of form items(label[,selection or default][,type]) title: str = "Form" # window title ) -> Union[dict[str, Any], None]: """ @@ -607,7 +607,7 @@ def popup_get_form( Alternatively, you can specify labels, types, and default values as `[(label1, type1, default1), (label2, type2, default2), ...]`. The following values can be specified for the type: `text`, `number`, `password`, `combo`, `list`, `date`, `file`, `files`, `folder`, `color`. - @see [tests/popup_get_form.py](/tests/popup_get_form.py) + @see [tests/popup_get_form_test.py](/tests/popup_get_form_test.py) """ # make form layout item_labels = [] @@ -617,12 +617,14 @@ def popup_get_form( it_key = f"-formitem{i}" if isinstance(it, tuple) or isinstance(it, list): label = it[0] - itype = it[1] if len(it) >= 2 else "text" - default_value = it[2] if len(it) >= 3 else "" + default_value = it[1] if len(it) >= 2 else "" + itype = it[2] if len(it) >= 3 else "text" + if isinstance(default_value, tuple) or isinstance(default_value, list): + itype = "list" else: label = it - itype = "text" default_value = "" + itype = "text" # for making result item_labels.append(label) item_converters.append(None) diff --git a/TkEasyGUI/widgets.py b/TkEasyGUI/widgets.py index baef080..bfbd31d 100644 --- a/TkEasyGUI/widgets.py +++ b/TkEasyGUI/widgets.py @@ -937,7 +937,7 @@ def __init__( self.key: str|int|None = key if (self.key is not None) and (self.key != ""): if not register_element_key(self.key): # for checking unique key - raise TkEasyError(f"Element key is not unique: {self.key}") + pass # raise TkEasyError(f"Element key is not unique: {self.key}") if self.has_value and (self.key is None or self.key == ""): self.key = generate_element_id() self.element_type: str = element_type diff --git a/tests/popup_get_form_test.py b/tests/popup_get_form_test.py index c47492c..1561e28 100644 --- a/tests/popup_get_form_test.py +++ b/tests/popup_get_form_test.py @@ -2,14 +2,14 @@ result = eg.popup_get_form( [ - ["Name", "text"], - ["Age", "number"], - ["OS", "combo", ["Windows", "macOS", "Ubuntu"]], - ["Fruits", "list", ["Banana", "Orange", "Apple"]], - ["Password", "password"], - ["Date", "date"], - ["File", "file"], - ["Theme Color", "color"], + ["Name", "kujira"], + ["Age", 20, "number"], + ["OS",["Windows", "macOS", "Ubuntu"],"combo"], + ["Fruits", ["Banana", "Orange"], "list",], + ["Password", "", "password"], + ["Date", "", "date"], + ["File", "", "file"], + ["Theme Color", "", "color"], ], title="Form Test", )