回答編集履歴
1
追記
answer
CHANGED
@@ -47,4 +47,28 @@
|
|
47
47
|
OptionMenu には、通常のメニューと同じように項目を追加出来ます。
|
48
48
|
|
49
49
|
…が、内部関数(_setit) が必要になる事から、恐らく想定されてない用途なので、
|
50
|
-
(項目がネストしないなら、)Comboboxを入力禁止にして使う方が良いかもしれないです。
|
50
|
+
(項目がネストしないなら、)Comboboxを入力禁止にして使う方が良いかもしれないです。
|
51
|
+
|
52
|
+
----
|
53
|
+
追記: OptionMenuの要素を更新する例
|
54
|
+
|
55
|
+
```python
|
56
|
+
|
57
|
+
## class Application create_widgets
|
58
|
+
|
59
|
+
self.f1_button = tk.Button(self.f1, text = 'update', width = 30, command = lambda : f1_file.control(Read, var, self))
|
60
|
+
|
61
|
+
|
62
|
+
## class File
|
63
|
+
|
64
|
+
def control(self, file_type, path_object, app):
|
65
|
+
self._file_path = self._get_filepath(path_object)
|
66
|
+
self._set_items(self._get_items(file_type))
|
67
|
+
|
68
|
+
# ※ このコードはここには書かず Applicationクラスのメソッドにした方がよい。
|
69
|
+
opt = app.f2_opt["menu"]
|
70
|
+
opt.delete(0, "last")
|
71
|
+
for line in file_contents:
|
72
|
+
opt.add_command(label=line.strip()) # TODO: add command=
|
73
|
+
app.f2_opt_variable.set("")
|
74
|
+
```
|