teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

追記

2021/10/18 06:41

投稿

saya24
saya24

スコア258

title CHANGED
File without changes
body CHANGED
@@ -162,4 +162,50 @@
162
162
  generate_frame(root)
163
163
 
164
164
  root.mainloop()
165
+ ```
166
+
167
+ ### 20211018 1540 追記
168
+ ```python
169
+ #関数
170
+ def open_FileDialog(ent, btn):
171
+ def error_handler():
172
+ error_message(msg001)
173
+ ent.configure(state='normal')
174
+ ent.delete(0, tk.END)
175
+ ent.configure(state='disabled')
176
+
177
+ file = filedialog.askopenfilename() #パス取得
178
+
179
+ if btn == 0:
180
+ if file == ent_OutputPath.get(): #入力と出力で同じファイル指定を受付けないように
181
+ btn_AssignInputFile.focus_set()
182
+ error_handler()
183
+ return
184
+ else:
185
+ if file == ent_InputPath.get(): #入力と出力で同じファイル指定を受付けないように
186
+ btn_AssignOutputFile.focus_set()
187
+ error_handler()
188
+ return
189
+
190
+ ent.configure(state='normal')
191
+ ent.delete(0, tk.END)
192
+ ent.insert(tk.END, file)
193
+ ent.configure(state='disabled')
194
+ btn_ReturnMenu.focus_set()
195
+ ```
196
+
197
+ ```python
198
+ # 入力ファイル指定ボタン、選択ファイル格納テキストボックス配置
199
+ ent_InputPath = tk.Entry(frmIOMenu, state="disabled")
200
+ ent_InputPath.grid(row=0, column=1, columnspan=9, sticky=tk.E + tk.W + tk.N + tk.S)
201
+
202
+ btn_AssignInputFile = tk.Button(frmIOMenu, text = "入力ファイル指定", command=lambda : open_FileDialog(ent_InputPath, 0))
203
+ btn_AssignInputFile.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S)
204
+
205
+ # 出力ファイル指定ボタン、選択ファイル格納テキストボックス配置
206
+ ent_OutputPath = tk.Entry(frmIOMenu, state="disabled")
207
+ ent_OutputPath.grid(row=1, column=1, columnspan=9, sticky=tk.E + tk.W + tk.N + tk.S)
208
+
209
+ btn_AssignOutputFile = tk.Button(frmIOMenu, text = "出力ファイル指定", command=lambda : open_FileDialog(ent_OutputPath, 1))
210
+ btn_AssignOutputFile.grid(row=1, column=0, sticky=tk.E + tk.W + tk.N + tk.S)
165
211
  ```