質問編集履歴

2

コード間違い

2020/07/03 06:10

投稿

saya24
saya24

スコア222

test CHANGED
File without changes
test CHANGED
@@ -66,16 +66,12 @@
66
66
 
67
67
  btn2 = ttk.Button(self, text="Mail")
68
68
 
69
- btn2.bind('<Return>', self.openDialog3)
70
-
71
69
  btn2.pack(fill = BOTH, expand=True)
72
70
 
73
71
 
74
72
 
75
73
  btn3 = ttk.Button(self, text="Job")
76
74
 
77
- btn3.bind('<Return>', self.openDialog2)
78
-
79
75
  btn3.pack(fill = BOTH, expand=True)
80
76
 
81
77
 

1

簡単なコードと実行環境の違いの画像

2020/07/03 06:10

投稿

saya24
saya24

スコア222

test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,523 @@
15
15
 
16
16
 
17
17
  ご見解を頂けたら幸いです、よろしくお願いします。
18
+
19
+
20
+
21
+ ### 20200703 14:45 現況コードと画像追加
22
+
23
+
24
+
25
+ ```Python
26
+
27
+ from tkinter import *
28
+
29
+ import tkinter.ttk as ttk
30
+
31
+ import tkinter.scrolledtext as tksc
32
+
33
+ import math
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+ class Apprication(ttk.Frame):
42
+
43
+
44
+
45
+ def __init__(self, app):
46
+
47
+
48
+
49
+
50
+
51
+ super().__init__(app)
52
+
53
+ self.pack(fill = BOTH, expand=True)
54
+
55
+
56
+
57
+ btn1 = ttk.Button(self, text="Script", command=self.openDialog1)
58
+
59
+ btn1.bind('<Return>', self.openDialog1)
60
+
61
+ btn1.pack(fill = BOTH, expand=True)
62
+
63
+ btn1.focus_set()
64
+
65
+
66
+
67
+ btn2 = ttk.Button(self, text="Mail")
68
+
69
+ btn2.bind('<Return>', self.openDialog3)
70
+
71
+ btn2.pack(fill = BOTH, expand=True)
72
+
73
+
74
+
75
+ btn3 = ttk.Button(self, text="Job")
76
+
77
+ btn3.bind('<Return>', self.openDialog2)
78
+
79
+ btn3.pack(fill = BOTH, expand=True)
80
+
81
+
82
+
83
+ btn4 = ttk.Button(self, text="Quit", command=app.quit)
84
+
85
+ btn4.bind('<Return>', lambda _: app.quit())
86
+
87
+ btn4.pack(fill = BOTH, expand=True)
88
+
89
+
90
+
91
+ self.menu()
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+ def menu(self):
100
+
101
+ menu_top = Menu(app)
102
+
103
+ menu_file = Menu(menu_top, tearoff=False)
104
+
105
+ menu_open = Menu(menu_top, tearoff=False)
106
+
107
+
108
+
109
+ menu_help = Menu(menu_top, tearoff=False) #★
110
+
111
+
112
+
113
+
114
+
115
+ app.configure(menu=menu_top, bg="#F0FFFF")
116
+
117
+
118
+
119
+ menu_top.add_cascade (label='File(F)', menu=menu_file, underline=0)
120
+
121
+ #★menu_top.add_command(label='Help(H)', underline=0)
122
+
123
+ menu_top.add_cascade(label='Help(H)', menu=menu_help, underline=0) #★
124
+
125
+
126
+
127
+ menu_file.add_cascade(label='Open(O)', underline=0, menu=menu_open)
128
+
129
+ menu_open.add_command(label='Script(S)', underline=0, command=self.openDialog1)
130
+
131
+ menu_open.add_command(label='Job(J)', underline=0)
132
+
133
+ menu_open.add_command(label='Mail(M)', underline=0)
134
+
135
+ menu_file.add_command(label='Quit(Q)',underline=0, command=app.quit)
136
+
137
+
138
+
139
+ #★
140
+
141
+ menu_help.add_command(label='Display(D)', underline=0)
142
+
143
+ menu_help.add_command(label='Version(V)', underline=0)
144
+
145
+ #★
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+ # 子画面①開く Script Menu
156
+
157
+ def openDialog1(self, event=None):
158
+
159
+
160
+
161
+ global pngfile
162
+
163
+
164
+
165
+ # メモリにDB一覧を作る
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+ self.dialog = Toplevel(self)
176
+
177
+ self.dialog.title("Script Menu")
178
+
179
+
180
+
181
+ #フォームサイズを実行端末から導き、ド真中に配置表示
182
+
183
+ lw = math.ceil(ww * 0.408)
184
+
185
+ lh = math.ceil(wh * 0.477)
186
+
187
+ self.dialog.geometry(str(lw)+"x"+str(lh)+"+"+str(int(ww/2-lw/2))+"+"+str(int(wh/2-lh/2)))
188
+
189
+
190
+
191
+ self.dialog.configure(bg="#F0FFFF")
192
+
193
+ self.dialog.resizable(0,0)
194
+
195
+ self.dialog.protocol('WM_DELETE_WINDOW', (lambda: 'pass')())
196
+
197
+
198
+
199
+ # 当該ダイアログのカーソルを変更し、関数側でもカーソルを変更できるように
200
+
201
+ self.dialog['cursor'] = 'hand2'
202
+
203
+ self.this = self.dialog
204
+
205
+
206
+
207
+ # modalに
208
+
209
+ self.dialog.grab_set()
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+ # DataBaseを選択するためのコンボボックス
218
+
219
+ self.cmbox1 = ttk.Combobox(self.dialog, width=5, justify=CENTER, state='readonly', takefocus=1)
220
+
221
+ self.cmbox1.grid(row=0, column=0, padx=(10, 0), pady=(10,0), sticky=W+E)
222
+
223
+ self.cmbox1.focus_set()
224
+
225
+
226
+
227
+ # DataBaseという文字
228
+
229
+ self.txt1 = Entry(self.dialog, state="readonly", takefocus=1)
230
+
231
+ self.txt1.grid(row=0, column=1, columnspan=7, sticky=W+E, pady=(10,0))
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+ # 登録SQL文のコンボボックス
242
+
243
+ self.v2 = StringVar()
244
+
245
+ self.cmbox2 = ttk.Combobox(self.dialog, width=5, justify=CENTER, state='disable', textvariable=self.v2, takefocus=1)
246
+
247
+ self.cmbox2.grid(row=1, column=0, padx=(10, 0), sticky=W+E)
248
+
249
+
250
+
251
+ self.txt2 = Entry(self.dialog, state="readonly", takefocus=1)
252
+
253
+ self.txt2.grid(row=1, column=1, columnspan=7, sticky=W+E)
254
+
255
+
256
+
257
+ # 登録SQL文のコンボボックスの有効無効切替え
258
+
259
+ self.chbox1_var = BooleanVar(self.dialog)
260
+
261
+ self.chbox1 = Checkbutton(self.dialog, variable=self.chbox1_var, bg="#F0FFFF", takefocus=1, activebackground="#F0FFFF")
262
+
263
+ self.chbox1.grid(row=1, column=8)
264
+
265
+
266
+
267
+ self.btn4 = Button(self.dialog, text='Delete', state=DISABLED, takefocus=1)
268
+
269
+ self.btn4.grid(row=1, column=10, padx=(0,10), sticky=W+E)
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+ # 発行するSQL文の入力エリア
280
+
281
+ self.scrtxt1 = tksc.ScrolledText(self.dialog, bg="black", fg="orange", font=("Helvetica",11), insertbackground="orange", blockcursor=False, height=6, state="disable", takefocus=1)
282
+
283
+ self.scrtxt1.grid(row=2, column=0, columnspan=11, sticky=W+E, padx=10)
284
+
285
+
286
+
287
+ self.update()
288
+
289
+ scrtxt1_width = self.scrtxt1.winfo_width()
290
+
291
+ scrtxt1_height = self.scrtxt1.winfo_height()
292
+
293
+ middle_x = scrtxt1_width / 2
294
+
295
+ middle_y = scrtxt1_height / 2
296
+
297
+
298
+
299
+ self.cvs = Canvas(self.dialog, height=scrtxt1_height)
300
+
301
+ self.cvs.create_image(middle_x, middle_y, anchor=CENTER)
302
+
303
+ self.cvs.grid(row=2, column=0, columnspan=11, sticky=W+E, padx=10)
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+ self.lb1 = Label(self.dialog, bg="#F0FFFF", fg="red")
314
+
315
+ self.lb1.grid(row=3, column=0, padx=(10, 0), pady=(0, 20), sticky=N+W)
316
+
317
+
318
+
319
+ self.lb2 = Label(self.dialog, bg="#F0FFFF", fg="red")
320
+
321
+ self.lb2.grid(row=3, column=2, pady=(0, 20), sticky=N+W)
322
+
323
+
324
+
325
+ # SQL文の表示を許すか許さないかの切替え
326
+
327
+ self.chbox2_var = BooleanVar(self.dialog)
328
+
329
+ self.chbox2 = Checkbutton(self.dialog, variable=self.chbox2_var, bg="#F0FFFF", takefocus=1, activebackground="#F0FFFF")
330
+
331
+ self.chbox2.grid(row=3, column=8, pady=(0, 40), )
332
+
333
+
334
+
335
+ # ★SQL発行ボタン★
336
+
337
+ self.btn1 = Button(self.dialog, text='Execute', width=10, state=DISABLED, takefocus=1)
338
+
339
+ self.btn1.grid(row=3, column=10, pady=(0, 20), padx=(0,10), sticky=N)
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+ # SQL発行結果(表示専用)
350
+
351
+ self.scrtxt2 = tksc.ScrolledText(self.dialog, bg="SystemButtonFace", font=("Helvetica",11), height=6, takefocus=1)
352
+
353
+ self.scrtxt2.grid(row=4, column=0, columnspan=11, sticky=W+E, padx=10)
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+ # SQL登録ボタン
364
+
365
+ self.btn2 = Button(self.dialog, text='Save', state=DISABLED, takefocus=1)
366
+
367
+ self.btn2.grid(row=5, column=0, padx=(10,0), sticky=W+E)
368
+
369
+
370
+
371
+ # SQL登録ID
372
+
373
+ self.lb3 = Label(self.dialog, bg="black", fg="orange", width=7, takefocus=1)
374
+
375
+ self.lb3.grid(row=5, column=1, sticky=W+E)
376
+
377
+
378
+
379
+ self.txt3 = Entry(self.dialog, state='readonly', takefocus=1)
380
+
381
+ self.txt3.grid(row=5, column=2, columnspan=10, sticky=W+E, padx=(0,10))
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+ # EXCEL出力ボタン
392
+
393
+ self.btn3 = Button(self.dialog, text='Excel', state=DISABLED, takefocus=1)
394
+
395
+ self.btn3.grid(row=6, column=0, padx=(10,0), sticky=W+E)
396
+
397
+
398
+
399
+ self.prbar1 = ttk.Progressbar(self.dialog, orient=HORIZONTAL, length=100, mode='determinate')
400
+
401
+ self.prbar1.grid(row=6, column=1, columnspan=3, pady=(5,0), sticky=N+W)
402
+
403
+
404
+
405
+ # SQL文の提供を受けることを想定し インポートメニューを追加
406
+
407
+ btn5 = Button(self.dialog, text='Import', width=10, takefocus=1)
408
+
409
+ btn5.grid(row=6, column=8, pady=10)
410
+
411
+
412
+
413
+
414
+
415
+ # 閉じるボタン
416
+
417
+ btn4 = Button(self.dialog, text='Quit', command=self.closeDialog, width=10, takefocus=1)
418
+
419
+ btn4.grid(row=6, column=10, pady=10, padx=(0,10))
420
+
421
+ btn4.bind('<Return>', self.closeDialog)
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+ self.dialog.grid_rowconfigure(1, weight=1)
430
+
431
+ self.dialog.grid_rowconfigure(3, weight=1)
432
+
433
+
434
+
435
+ self.dialog.grid_columnconfigure(2, weight=1)
436
+
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+ # 子画面閉じる
448
+
449
+ def closeDialog(self, event=None):
450
+
451
+ self.dialog.destroy()
452
+
453
+
454
+
455
+
456
+
457
+
458
+
459
+ if __name__ == '__main__':
460
+
461
+
462
+
463
+ #世間でいうrootをappとしています
464
+
465
+ app = Tk()
466
+
467
+
468
+
469
+ #実行端末の画面サイズを取得
470
+
471
+ ww = app.winfo_screenwidth()
472
+
473
+ wh = app.winfo_screenheight()
474
+
475
+
476
+
477
+ app.update_idletasks()
478
+
479
+
480
+
481
+ #フォームサイズを実行端末から導き、ド真中に配置表示
482
+
483
+ lw = math.ceil(ww * 0.208)
484
+
485
+ lh = math.ceil(wh * 0.277)
486
+
487
+ app.geometry(str(lw)+"x"+str(lh)+"+"+str(int(ww/2-lw/2))+"+"+str(int(wh/2-lh/2)) )
488
+
489
+
490
+
491
+ #タイトルを指定
492
+
493
+ app.title("Main Menu")
494
+
495
+
496
+
497
+
498
+
499
+ #フォームの最大化、×ボタン操作を無効化
500
+
501
+ app.resizable(0,0)
502
+
503
+ app.protocol('WM_DELETE_WINDOW', (lambda: 'pass')())
504
+
505
+
506
+
507
+ # カーソル変更
508
+
509
+ app["cursor"] = "hand2"
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+ # フレームを作成する
518
+
519
+ frame = Apprication(app)
520
+
521
+ # 格納したTkインスタンスのmainloopで画面を起こす
522
+
523
+ app.mainloop()
524
+
525
+
526
+
527
+
528
+
529
+ ```
530
+
531
+ 端末Aでの実行(立ち上げ時メニューでSCRIPTを押してください)
532
+
533
+ ![大きな解像度での実行](da3c2e355f8d3d7529691b108898ffbf.png)
534
+
535
+ 端末Bでの実行(立ち上げ時メニューでSCRIPTを押してください)
536
+
537
+ ![SCRIPT](afc83e460605df03ba1b5238a4ae58f2.png)