質問編集履歴

3

追記

2021/12/05 01:56

投稿

saya24
saya24

スコア247

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
  初心者ゆえ、世間に紹介されている有用な技術の適用に苦戦しています、どなたかご見解を頂けますと幸いです。
30
30
 
31
-
31
+ ![menu](36acef643987306ae3c04f94986c61ab.png)![menu2](79f2b077c5ba4543dc6f0d816a3955e0.png)
32
32
 
33
33
  ```python
34
34
 

2

追記

2021/12/05 01:56

投稿

saya24
saya24

スコア247

test CHANGED
File without changes
test CHANGED
@@ -30,4 +30,484 @@
30
30
 
31
31
 
32
32
 
33
+ ```python
34
+
35
+ import tkinter as tk
36
+
37
+ import tkinter.ttk as ttk
38
+
39
+ import math
40
+
41
+ import os
42
+
43
+ import tkinter.messagebox as tkmb
44
+
45
+ from functools import partial
46
+
47
+ import datetime
48
+
49
+ from tkinter import simpledialog
50
+
51
+
52
+
53
+ #★
54
+
55
+ class MyDialog(simpledialog.Dialog):
56
+
57
+
58
+
59
+ def body(self, master):
60
+
61
+ self.var = tk.IntVar()
62
+
63
+ val_cmd = self.master.register(self.switchButtonState)
64
+
65
+ self.a = tk.Entry(master, validate="key", validatecommand=(val_cmd, '%P'))
66
+
67
+ self.a.pack()
68
+
69
+
70
+
71
+ self.a.focus_set()
72
+
73
+
74
+
75
+ def switchButtonState(self, P):
76
+
77
+ if len(P) == 0:
78
+
79
+ self.button1['state'] = tk.DISABLED
80
+
81
+ else:
82
+
83
+ self.button1['state'] = tk.NORMAL
84
+
85
+ return True
86
+
87
+
88
+
89
+ def buttonbox(self):
90
+
91
+ box = tk.Frame(self)
92
+
93
+ self.button1 = tk.Button(box, text="OK", width=10, command=self.ok, state=tk.DISABLED)
94
+
95
+ self.button1.pack(side=tk.LEFT, padx=5, pady=5)
96
+
97
+
98
+
99
+ box.pack()
100
+
101
+
102
+
103
+ def apply(self):
104
+
105
+ self.title = self.a.get()
106
+
107
+
108
+
109
+ def answer(self):
110
+
111
+ return self.title
112
+
113
+
114
+
115
+ #★
116
+
117
+ def resource_path(relative_path):
118
+
119
+ try:
120
+
121
+ base_path = sys._MEIPASS
122
+
123
+ except Exception:
124
+
125
+ base_path = os.path.abspath(".")
126
+
127
+
128
+
129
+ return os.path.join(base_path, relative_path)
130
+
131
+
132
+
133
+ def adjust_windowsize(root):
134
+
135
+ ww = root.winfo_screenwidth()
136
+
137
+ wh = root.winfo_screenheight()
138
+
139
+
140
+
141
+ lw = math.ceil(ww * 0.3208)
142
+
143
+ lh = math.ceil(wh * 0.477)
144
+
145
+
146
+
147
+ root.geometry(str(lw)+"x"+str(lh)+"+"+str(int(ww/2-lw/2))+"+"+str(int(wh/2-lh/2)))
148
+
149
+
150
+
151
+ def info_message(msg):
152
+
153
+ tkmb.showinfo("お知らせ", msg)
154
+
155
+
156
+
157
+ def abort_message(place, msg):
158
+
159
+ return tkmb.showerror(place, msg)
160
+
161
+
162
+
163
+
164
+
165
+ #★
166
+
167
+ def generate_frame(root):
168
+
169
+
170
+
171
+ def change_frame(frame):
172
+
173
+
174
+
175
+ frame.tkraise()
176
+
177
+
178
+
179
+ style = ttk.Style()
180
+
181
+ style.theme_use('winnative')
182
+
183
+ style.map("TCombobox",selectbackground=[('!readonly','!focus','SystemWindow'),('readonly','!focus','SystemButtonFace'),],)
184
+
185
+ style.configure("TButton", font=("Arial", 16))
186
+
187
+ style.configure("TFrame", background="#FFFFCC")
188
+
189
+ style.configure("TRadiobutton", background="#FFFFCC")
190
+
191
+ style.configure("TLabel", font=("Arial", 16), anchor='', background="#FFFFCC")
192
+
193
+ style.configure("TLabelframe", background="#FFFFCC", relief="sunken")
194
+
195
+ style.configure("TLabelframe.Label", foreground="red", font=("Arial", 16), background="#FFFFCC")
196
+
197
+
198
+
199
+
200
+
201
+ def get_Answer():
202
+
203
+ Q = MyDialog(frmConvMenu)
204
+
205
+
206
+
207
+ try:
208
+
209
+
210
+
211
+ #con = db()
212
+
213
+ #connection = con.db_Connect()
214
+
215
+ #cursor = connection.cursor()
216
+
217
+
218
+
219
+ #★★★ teamikleさん回答をうけ、ダイアログ未回答でも下記条件 TRUE動作になっていることを初めて把握...(ありがとうございます)
220
+
33
- (×ボタン押下されても OKボタンの押下バインドされたメソッドが動作する回避策でも 良いと考えています)
221
+ #★★★ 未回答をNoneで確認するの正解かもしない。 いずれにしても未回答が発生させないようにするには を学ぶ
222
+
223
+ if Q.answer() != "":
224
+
225
+ data = (Q.answer(), cmbox_Tbl1.get())
226
+
227
+ sql = "UPDATE M_TABLES SET NAME=? WHERE RECNO=?"
228
+
229
+ #cursor.execute(sql, data)
230
+
231
+
232
+
233
+ info_message("A table was updated")
234
+
235
+ else:
236
+
237
+ raise Exception("coudn't get an answer")
238
+
239
+
240
+
241
+ except Exception as e:
242
+
243
+ abort_message("E510", e)
244
+
245
+ return
246
+
247
+
248
+
249
+ finally:
250
+
251
+ None
252
+
253
+ #connection.commit()
254
+
255
+ #connection.close()
256
+
257
+
258
+
259
+
260
+
261
+ #★
262
+
263
+ frmMain = ttk.Frame(root, name="frmMain")
264
+
265
+ frmMain.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S)
266
+
267
+
268
+
269
+ btn_SettingMenu = ttk.Button(frmMain, text = "入出力定義")
270
+
271
+ btn_SettingMenu.pack(fill = tk.BOTH, expand=True)
272
+
273
+ btn_SettingMenu.bind('<Return>', lambda a: change_frame(frmIOMenu))
274
+
275
+
276
+
277
+ btn_SettingMenu = ttk.Button(frmMain, text = "変換定義", command=lambda: change_frame(frmConvMenu))
278
+
279
+ btn_SettingMenu.pack(fill = tk.BOTH, expand=True)
280
+
281
+ btn_SettingMenu.bind('<Return>', lambda a: change_frame(frmConvMenu))
282
+
283
+
284
+
285
+ btn_RunMenu = ttk.Button(frmMain, text = "実行メニュー")
286
+
287
+ btn_RunMenu.pack(fill = tk.BOTH, expand=True)
288
+
289
+ btn_RunMenu.focus_set()
290
+
291
+
292
+
293
+ btn_Close = ttk.Button(frmMain, text = "終了", command=root.destroy)
294
+
295
+ btn_Close.pack(fill = tk.BOTH, expand=True)
296
+
297
+
298
+
299
+ #★
300
+
301
+ frmConvMenu = ttk.Frame(root, name="frmConvMenu")
302
+
303
+ frmConvMenu.grid_rowconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], weight=1)
304
+
305
+ frmConvMenu.grid_columnconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], weight=1, minsize=40)
306
+
307
+ frmConvMenu.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S)
308
+
309
+
310
+
311
+
312
+
313
+ lbfrm1 = ttk.LabelFrame(frmConvMenu, text="対応表登録", labelanchor="n")
314
+
315
+ lbfrm1.grid(row=1, column=0, rowspan=5, columnspan=10, sticky=tk.W + tk.E + tk.N + tk.S, padx=(10,10))
316
+
317
+
318
+
319
+
320
+
321
+ lst_tmp = [1,2,3]
322
+
323
+ cmbox_Tbl1 = ttk.Combobox(frmConvMenu, height=3, font=("Arial", 16), state="readonly", values=lst_tmp)
324
+
325
+ cmbox_Tbl1.grid(row=2, column=1, columnspan=8, sticky=tk.E + tk.W, pady=(10,0), padx=(10,10))
326
+
327
+
328
+
329
+ frmTmp = ttk.Frame(frmConvMenu, name="frmTmp")
330
+
331
+ frmTmp.grid(row=3, column=1, columnspan=8, sticky=tk.E + tk.W + tk.N + tk.S, padx=(10,10), pady=(10,0))
332
+
333
+
334
+
335
+ lab_Select = ttk.Label(frmTmp, text="種類", font=("Arial", 11))
336
+
337
+ lab_Select.grid(row=0, column=1, sticky=tk.E + tk.W)
338
+
339
+
340
+
341
+ lab_Sheet = ttk.Label(frmTmp, text="シート", font=("Arial", 11))
342
+
343
+ lab_Sheet.grid(row=0, column=3, sticky=tk.E + tk.W)
344
+
345
+
346
+
347
+ lab_FCell = ttk.Label(frmTmp, text="開始", font=("Arial", 11))
348
+
349
+ lab_FCell.grid(row=0, column=4, sticky=tk.E + tk.W)
350
+
351
+
352
+
353
+ lab_TCell = ttk.Label(frmTmp, text="終了", font=("Arial", 11))
354
+
355
+ lab_TCell.grid(row=0, column=5, sticky=tk.E + tk.W)
356
+
357
+
358
+
359
+ lab_Key = ttk.Label(frmTmp, text="キー", font=("Arial", 11))
360
+
361
+ lab_Key.grid(row=0, column=6, sticky=tk.E + tk.W)
362
+
363
+
364
+
365
+ lab_Initial = ttk.Label(frmTmp, text="初期化", font=("Arial", 11))
366
+
367
+ lab_Initial.grid(row=0, column=7, sticky=tk.E + tk.W)
368
+
369
+
370
+
371
+ global radioValue
372
+
373
+ radioValue = tk.IntVar()
374
+
375
+ rb1 = ttk.Radiobutton(frmTmp, text="Tab", variable=radioValue, value=0)
376
+
377
+ rb1.grid(row=1, column=0, sticky=tk.S)
378
+
379
+
380
+
381
+ rb2 = ttk.Radiobutton(frmTmp, text="Comma", variable=radioValue, value=1)
382
+
383
+ rb2.grid(row=1, column=1, sticky=tk.S)
384
+
385
+
386
+
387
+ rb3 = ttk.Radiobutton(frmTmp, text="Excel", variable=radioValue, value=2)
388
+
389
+ rb3.grid(row=1, column=2, sticky=tk.S)
390
+
391
+ radioValue.set(2)
392
+
393
+
394
+
395
+ btn_Select = ttk.Button(frmConvMenu, text = "選択", command=get_Answer)
396
+
397
+ btn_Select.grid(row=4, column=1, columnspan=1, sticky=tk.E + tk.W, padx=(10,0), pady=(0,10))
398
+
399
+
400
+
401
+ btn_Upload = ttk.Button(frmConvMenu, text = "Up", state=tk.DISABLED, command=lambda : importCtrl(radioValue.get()))
402
+
403
+ btn_Upload.grid(row=4, column=2, columnspan=1, sticky=tk.E + tk.W, pady=(0,10))
404
+
405
+
406
+
407
+ ent_UpPath = ttk.Entry(frmConvMenu, state=tk.DISABLED, font=("Arial", 11), width=100)
408
+
409
+ ent_UpPath.grid(row=4, column=3, columnspan=6, sticky=tk.E + tk.W, padx=(0,10), pady=(0,10))
410
+
411
+
412
+
413
+ cmbox_Sheet = ttk.Combobox(frmTmp, width=7, height=3, font=("Arial", 16), state=tk.DISABLED)
414
+
415
+ cmbox_Sheet.grid(row=1, column=3, sticky=tk.E + tk.W + tk.S)
416
+
417
+
418
+
419
+ cmbox_FCell = ttk.Combobox(frmTmp, width=3, height=3, font=("Arial", 16), state=tk.DISABLED)
420
+
421
+ cmbox_FCell.grid(row=1, column=4, sticky=tk.E + tk.W + tk.S)
422
+
423
+
424
+
425
+ cmbox_TCell = ttk.Combobox(frmTmp, width=3, height=3, font=("Arial", 16), state=tk.DISABLED)
426
+
427
+ cmbox_TCell.grid(row=1, column=5, sticky=tk.E + tk.W + tk.S)
428
+
429
+
430
+
431
+ cmbox_Key = ttk.Combobox(frmTmp, width=3, height=3, font=("Arial", 16), state=tk.DISABLED)
432
+
433
+ cmbox_Key.grid(row=1, column=6, sticky=tk.E + tk.W + tk.S)
434
+
435
+
436
+
437
+ reqinitial = tk.BooleanVar()
438
+
439
+ reqinitial.set(False)
440
+
441
+ chk_Initial = tk.Checkbutton(frmTmp, variable=reqinitial, bg="#FFFFCC", state=tk.DISABLED)
442
+
443
+ chk_Initial.grid(row=1, column=7, sticky=tk.E + tk.W + tk.S)
444
+
445
+
446
+
447
+ btn_TblM = ttk.Button(frmConvMenu, text = "個別編集", state=tk.DISABLED)
448
+
449
+ btn_TblM.grid(row=5, column=1, columnspan=8, sticky=tk.E + tk.W, padx=(10,10))
450
+
451
+
452
+
453
+ lbfrm2 = ttk.LabelFrame(frmConvMenu, text="変換定義", labelanchor="n")
454
+
455
+ lbfrm2.grid(row=6, column=0, rowspan=5, columnspan=10, sticky=tk.W + tk.E + tk.N + tk.S, padx=(10,10), pady=(20,0))
456
+
457
+
458
+
459
+ cmbox_Tbl2 = ttk.Combobox(frmConvMenu, height=3, font=("Arial", 16), state="readonly")
460
+
461
+ cmbox_Tbl2.grid(row=7, column=1, columnspan=8, sticky=tk.E + tk.W, pady=(30,0), padx=(10,10))
462
+
463
+
464
+
465
+ btn_ConvM = ttk.Button(frmConvMenu, text = "変更定義の 追加 / 変更 / 削除", state=tk.DISABLED)
466
+
467
+ btn_ConvM.grid(row=8, column=1, columnspan=8, sticky=tk.E + tk.W, padx=(10,10))
468
+
469
+
470
+
471
+ btn_Inq = ttk.Button(frmConvMenu, text = "変更定義の 一覧参照", state=tk.DISABLED)
472
+
473
+ btn_Inq.grid(row=9, column=1, columnspan=8, sticky=tk.E + tk.W, padx=(10,10))
474
+
475
+
476
+
477
+ btn_ReturnMenu = ttk.Button(frmConvMenu, text = "閉じる", command=lambda: change_frame(frmMain))
478
+
479
+ btn_ReturnMenu.grid(row=11, column=8, sticky=tk.E + tk.W, padx=(0,10))
480
+
481
+
482
+
483
+ #★
484
+
485
+ frmMain.tkraise()
486
+
487
+
488
+
489
+ #★
490
+
491
+ if __name__ == "__main__":
492
+
493
+ root = tk.Tk()
494
+
495
+ adjust_windowsize(root)
496
+
497
+ root.title("TkInterの勉強")
498
+
499
+ root.grid_columnconfigure([0,1, 2, 3, 4, 5, 6, 7, 8, 9], weight=1)
500
+
501
+ root.grid_rowconfigure([0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], weight=1)
502
+
503
+ root.resizable(0,0)
504
+
505
+ root.protocol('WM_DELETE_WINDOW', (lambda: 'pass')())
506
+
507
+ root["cursor"] = "hand2"
508
+
509
+ generate_frame(root)
510
+
511
+ root.mainloop()
512
+
513
+ ```

1

誤記

2021/12/05 01:48

投稿

saya24
saya24

スコア247

test CHANGED
File without changes
test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
 
24
24
 
25
- 現在 適用したダイアログの×ボタンが有効であるため、これを故意に操作してしまうと以下エラーを招いてしまいます。
25
+ 現在 適用したダイアログの×ボタンが有効であるため、これを故意に操作してしまうと以下エラーを招いてしまいます。
26
26
 
27
27
  ![イメージ説明](b34a909fcee1d6b264a159c971e2cb92.png)
28
28