Skip to content

Commit

Permalink
フォームダイアログの仕様を変更 #80
Browse files Browse the repository at this point in the history
  • Loading branch information
kujirahand committed Nov 11, 2024
1 parent 0935bae commit 0443deb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions TkEasyGUI/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand All @@ -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 = []
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion TkEasyGUI/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tests/popup_get_form_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down

0 comments on commit 0443deb

Please sign in to comment.