質問編集履歴
2
コード間違い
title
CHANGED
File without changes
|
body
CHANGED
@@ -32,11 +32,9 @@
|
|
32
32
|
btn1.focus_set()
|
33
33
|
|
34
34
|
btn2 = ttk.Button(self, text="Mail")
|
35
|
-
btn2.bind('<Return>', self.openDialog3)
|
36
35
|
btn2.pack(fill = BOTH, expand=True)
|
37
36
|
|
38
37
|
btn3 = ttk.Button(self, text="Job")
|
39
|
-
btn3.bind('<Return>', self.openDialog2)
|
40
38
|
btn3.pack(fill = BOTH, expand=True)
|
41
39
|
|
42
40
|
btn4 = ttk.Button(self, text="Quit", command=app.quit)
|
1
簡単なコードと実行環境の違いの画像
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,4 +6,264 @@
|
|
6
6
|
|
7
7
|
自分の開発端末で表示されてたイメージ同様、縦横の縮尺率だけが違うだけの 表示を達成するには どういった設定を行う・気を付ければよいでしょうか
|
8
8
|
|
9
|
-
ご見解を頂けたら幸いです、よろしくお願いします。
|
9
|
+
ご見解を頂けたら幸いです、よろしくお願いします。
|
10
|
+
|
11
|
+
### 20200703 14:45 現況コードと画像追加
|
12
|
+
|
13
|
+
```Python
|
14
|
+
from tkinter import *
|
15
|
+
import tkinter.ttk as ttk
|
16
|
+
import tkinter.scrolledtext as tksc
|
17
|
+
import math
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
class Apprication(ttk.Frame):
|
22
|
+
|
23
|
+
def __init__(self, app):
|
24
|
+
|
25
|
+
|
26
|
+
super().__init__(app)
|
27
|
+
self.pack(fill = BOTH, expand=True)
|
28
|
+
|
29
|
+
btn1 = ttk.Button(self, text="Script", command=self.openDialog1)
|
30
|
+
btn1.bind('<Return>', self.openDialog1)
|
31
|
+
btn1.pack(fill = BOTH, expand=True)
|
32
|
+
btn1.focus_set()
|
33
|
+
|
34
|
+
btn2 = ttk.Button(self, text="Mail")
|
35
|
+
btn2.bind('<Return>', self.openDialog3)
|
36
|
+
btn2.pack(fill = BOTH, expand=True)
|
37
|
+
|
38
|
+
btn3 = ttk.Button(self, text="Job")
|
39
|
+
btn3.bind('<Return>', self.openDialog2)
|
40
|
+
btn3.pack(fill = BOTH, expand=True)
|
41
|
+
|
42
|
+
btn4 = ttk.Button(self, text="Quit", command=app.quit)
|
43
|
+
btn4.bind('<Return>', lambda _: app.quit())
|
44
|
+
btn4.pack(fill = BOTH, expand=True)
|
45
|
+
|
46
|
+
self.menu()
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
def menu(self):
|
51
|
+
menu_top = Menu(app)
|
52
|
+
menu_file = Menu(menu_top, tearoff=False)
|
53
|
+
menu_open = Menu(menu_top, tearoff=False)
|
54
|
+
|
55
|
+
menu_help = Menu(menu_top, tearoff=False) #★
|
56
|
+
|
57
|
+
|
58
|
+
app.configure(menu=menu_top, bg="#F0FFFF")
|
59
|
+
|
60
|
+
menu_top.add_cascade (label='File(F)', menu=menu_file, underline=0)
|
61
|
+
#★menu_top.add_command(label='Help(H)', underline=0)
|
62
|
+
menu_top.add_cascade(label='Help(H)', menu=menu_help, underline=0) #★
|
63
|
+
|
64
|
+
menu_file.add_cascade(label='Open(O)', underline=0, menu=menu_open)
|
65
|
+
menu_open.add_command(label='Script(S)', underline=0, command=self.openDialog1)
|
66
|
+
menu_open.add_command(label='Job(J)', underline=0)
|
67
|
+
menu_open.add_command(label='Mail(M)', underline=0)
|
68
|
+
menu_file.add_command(label='Quit(Q)',underline=0, command=app.quit)
|
69
|
+
|
70
|
+
#★
|
71
|
+
menu_help.add_command(label='Display(D)', underline=0)
|
72
|
+
menu_help.add_command(label='Version(V)', underline=0)
|
73
|
+
#★
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
# 子画面①開く Script Menu
|
79
|
+
def openDialog1(self, event=None):
|
80
|
+
|
81
|
+
global pngfile
|
82
|
+
|
83
|
+
# メモリにDB一覧を作る
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
self.dialog = Toplevel(self)
|
89
|
+
self.dialog.title("Script Menu")
|
90
|
+
|
91
|
+
#フォームサイズを実行端末から導き、ド真中に配置表示
|
92
|
+
lw = math.ceil(ww * 0.408)
|
93
|
+
lh = math.ceil(wh * 0.477)
|
94
|
+
self.dialog.geometry(str(lw)+"x"+str(lh)+"+"+str(int(ww/2-lw/2))+"+"+str(int(wh/2-lh/2)))
|
95
|
+
|
96
|
+
self.dialog.configure(bg="#F0FFFF")
|
97
|
+
self.dialog.resizable(0,0)
|
98
|
+
self.dialog.protocol('WM_DELETE_WINDOW', (lambda: 'pass')())
|
99
|
+
|
100
|
+
# 当該ダイアログのカーソルを変更し、関数側でもカーソルを変更できるように
|
101
|
+
self.dialog['cursor'] = 'hand2'
|
102
|
+
self.this = self.dialog
|
103
|
+
|
104
|
+
# modalに
|
105
|
+
self.dialog.grab_set()
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
# DataBaseを選択するためのコンボボックス
|
110
|
+
self.cmbox1 = ttk.Combobox(self.dialog, width=5, justify=CENTER, state='readonly', takefocus=1)
|
111
|
+
self.cmbox1.grid(row=0, column=0, padx=(10, 0), pady=(10,0), sticky=W+E)
|
112
|
+
self.cmbox1.focus_set()
|
113
|
+
|
114
|
+
# DataBaseという文字
|
115
|
+
self.txt1 = Entry(self.dialog, state="readonly", takefocus=1)
|
116
|
+
self.txt1.grid(row=0, column=1, columnspan=7, sticky=W+E, pady=(10,0))
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
# 登録SQL文のコンボボックス
|
122
|
+
self.v2 = StringVar()
|
123
|
+
self.cmbox2 = ttk.Combobox(self.dialog, width=5, justify=CENTER, state='disable', textvariable=self.v2, takefocus=1)
|
124
|
+
self.cmbox2.grid(row=1, column=0, padx=(10, 0), sticky=W+E)
|
125
|
+
|
126
|
+
self.txt2 = Entry(self.dialog, state="readonly", takefocus=1)
|
127
|
+
self.txt2.grid(row=1, column=1, columnspan=7, sticky=W+E)
|
128
|
+
|
129
|
+
# 登録SQL文のコンボボックスの有効無効切替え
|
130
|
+
self.chbox1_var = BooleanVar(self.dialog)
|
131
|
+
self.chbox1 = Checkbutton(self.dialog, variable=self.chbox1_var, bg="#F0FFFF", takefocus=1, activebackground="#F0FFFF")
|
132
|
+
self.chbox1.grid(row=1, column=8)
|
133
|
+
|
134
|
+
self.btn4 = Button(self.dialog, text='Delete', state=DISABLED, takefocus=1)
|
135
|
+
self.btn4.grid(row=1, column=10, padx=(0,10), sticky=W+E)
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
# 発行するSQL文の入力エリア
|
141
|
+
self.scrtxt1 = tksc.ScrolledText(self.dialog, bg="black", fg="orange", font=("Helvetica",11), insertbackground="orange", blockcursor=False, height=6, state="disable", takefocus=1)
|
142
|
+
self.scrtxt1.grid(row=2, column=0, columnspan=11, sticky=W+E, padx=10)
|
143
|
+
|
144
|
+
self.update()
|
145
|
+
scrtxt1_width = self.scrtxt1.winfo_width()
|
146
|
+
scrtxt1_height = self.scrtxt1.winfo_height()
|
147
|
+
middle_x = scrtxt1_width / 2
|
148
|
+
middle_y = scrtxt1_height / 2
|
149
|
+
|
150
|
+
self.cvs = Canvas(self.dialog, height=scrtxt1_height)
|
151
|
+
self.cvs.create_image(middle_x, middle_y, anchor=CENTER)
|
152
|
+
self.cvs.grid(row=2, column=0, columnspan=11, sticky=W+E, padx=10)
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
self.lb1 = Label(self.dialog, bg="#F0FFFF", fg="red")
|
158
|
+
self.lb1.grid(row=3, column=0, padx=(10, 0), pady=(0, 20), sticky=N+W)
|
159
|
+
|
160
|
+
self.lb2 = Label(self.dialog, bg="#F0FFFF", fg="red")
|
161
|
+
self.lb2.grid(row=3, column=2, pady=(0, 20), sticky=N+W)
|
162
|
+
|
163
|
+
# SQL文の表示を許すか許さないかの切替え
|
164
|
+
self.chbox2_var = BooleanVar(self.dialog)
|
165
|
+
self.chbox2 = Checkbutton(self.dialog, variable=self.chbox2_var, bg="#F0FFFF", takefocus=1, activebackground="#F0FFFF")
|
166
|
+
self.chbox2.grid(row=3, column=8, pady=(0, 40), )
|
167
|
+
|
168
|
+
# ★SQL発行ボタン★
|
169
|
+
self.btn1 = Button(self.dialog, text='Execute', width=10, state=DISABLED, takefocus=1)
|
170
|
+
self.btn1.grid(row=3, column=10, pady=(0, 20), padx=(0,10), sticky=N)
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
# SQL発行結果(表示専用)
|
176
|
+
self.scrtxt2 = tksc.ScrolledText(self.dialog, bg="SystemButtonFace", font=("Helvetica",11), height=6, takefocus=1)
|
177
|
+
self.scrtxt2.grid(row=4, column=0, columnspan=11, sticky=W+E, padx=10)
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
# SQL登録ボタン
|
183
|
+
self.btn2 = Button(self.dialog, text='Save', state=DISABLED, takefocus=1)
|
184
|
+
self.btn2.grid(row=5, column=0, padx=(10,0), sticky=W+E)
|
185
|
+
|
186
|
+
# SQL登録ID
|
187
|
+
self.lb3 = Label(self.dialog, bg="black", fg="orange", width=7, takefocus=1)
|
188
|
+
self.lb3.grid(row=5, column=1, sticky=W+E)
|
189
|
+
|
190
|
+
self.txt3 = Entry(self.dialog, state='readonly', takefocus=1)
|
191
|
+
self.txt3.grid(row=5, column=2, columnspan=10, sticky=W+E, padx=(0,10))
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
# EXCEL出力ボタン
|
197
|
+
self.btn3 = Button(self.dialog, text='Excel', state=DISABLED, takefocus=1)
|
198
|
+
self.btn3.grid(row=6, column=0, padx=(10,0), sticky=W+E)
|
199
|
+
|
200
|
+
self.prbar1 = ttk.Progressbar(self.dialog, orient=HORIZONTAL, length=100, mode='determinate')
|
201
|
+
self.prbar1.grid(row=6, column=1, columnspan=3, pady=(5,0), sticky=N+W)
|
202
|
+
|
203
|
+
# SQL文の提供を受けることを想定し インポートメニューを追加
|
204
|
+
btn5 = Button(self.dialog, text='Import', width=10, takefocus=1)
|
205
|
+
btn5.grid(row=6, column=8, pady=10)
|
206
|
+
|
207
|
+
|
208
|
+
# 閉じるボタン
|
209
|
+
btn4 = Button(self.dialog, text='Quit', command=self.closeDialog, width=10, takefocus=1)
|
210
|
+
btn4.grid(row=6, column=10, pady=10, padx=(0,10))
|
211
|
+
btn4.bind('<Return>', self.closeDialog)
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
self.dialog.grid_rowconfigure(1, weight=1)
|
216
|
+
self.dialog.grid_rowconfigure(3, weight=1)
|
217
|
+
|
218
|
+
self.dialog.grid_columnconfigure(2, weight=1)
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
# 子画面閉じる
|
225
|
+
def closeDialog(self, event=None):
|
226
|
+
self.dialog.destroy()
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
if __name__ == '__main__':
|
231
|
+
|
232
|
+
#世間でいうrootをappとしています
|
233
|
+
app = Tk()
|
234
|
+
|
235
|
+
#実行端末の画面サイズを取得
|
236
|
+
ww = app.winfo_screenwidth()
|
237
|
+
wh = app.winfo_screenheight()
|
238
|
+
|
239
|
+
app.update_idletasks()
|
240
|
+
|
241
|
+
#フォームサイズを実行端末から導き、ド真中に配置表示
|
242
|
+
lw = math.ceil(ww * 0.208)
|
243
|
+
lh = math.ceil(wh * 0.277)
|
244
|
+
app.geometry(str(lw)+"x"+str(lh)+"+"+str(int(ww/2-lw/2))+"+"+str(int(wh/2-lh/2)) )
|
245
|
+
|
246
|
+
#タイトルを指定
|
247
|
+
app.title("Main Menu")
|
248
|
+
|
249
|
+
|
250
|
+
#フォームの最大化、×ボタン操作を無効化
|
251
|
+
app.resizable(0,0)
|
252
|
+
app.protocol('WM_DELETE_WINDOW', (lambda: 'pass')())
|
253
|
+
|
254
|
+
# カーソル変更
|
255
|
+
app["cursor"] = "hand2"
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
# フレームを作成する
|
260
|
+
frame = Apprication(app)
|
261
|
+
# 格納したTkインスタンスのmainloopで画面を起こす
|
262
|
+
app.mainloop()
|
263
|
+
|
264
|
+
|
265
|
+
```
|
266
|
+
端末Aでの実行(立ち上げ時メニューでSCRIPTを押してください)
|
267
|
+

|
268
|
+
端末Bでの実行(立ち上げ時メニューでSCRIPTを押してください)
|
269
|
+

|