質問編集履歴
3
報告
title
CHANGED
File without changes
|
body
CHANGED
@@ -224,4 +224,13 @@
|
|
224
224
|
|
225
225
|
root.mainloop()
|
226
226
|
```
|
227
|
-

|
227
|
+

|
228
|
+
### 1021 1540 最終的にこうなり、満足!
|
229
|
+

|
230
|
+
```python
|
231
|
+
frmIOMenu = tk.Frame(root, bg="red")
|
232
|
+
|
233
|
+
frmIOMenu.grid_rowconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8], weight=1)
|
234
|
+
frmIOMenu.grid_columnconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], weight=1, minsize=40)
|
235
|
+
frmIOMenu.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S)
|
236
|
+
```
|
2
誤記訂正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
ちゃんと座標形式で画面設計を前もって行い
|
2
|
-
それにもとづい
|
2
|
+
それにもとづいてWidget配置(GRID)を行っているのですが 毎回毎回自分が意図したようにならず 本当に困っています。
|
3
3
|
|
4
4
|
### 質問
|
5
5
|
なぜ意図した表示が行われないのか、どこを変更すれば 設計のように表示されるか? ご教示頂けますでしょうか?
|
6
|
-
|
6
|
+
TkInterで画面を作る都度、プログラム以前自分に何かの能力が欠落しているんじゃないかと 悩まされます。
|
7
7
|
|
8
8
|
|
9
9
|
!
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,8 +8,85 @@
|
|
8
8
|
|
9
9
|
!
|
10
10
|

|
11
|
+
|
12
|
+
### 1021 1016 提示コードを全体に差替え、下段に実行時のメニュー画像を追加
|
11
13
|
```Python
|
14
|
+
# tkinterのインポート
|
15
|
+
import tkinter as tk
|
16
|
+
import tkinter.ttk as ttk
|
17
|
+
import math
|
18
|
+
import os
|
19
|
+
from tkinter import filedialog
|
20
|
+
import tkinter.messagebox as tkmb
|
21
|
+
import openpyxl
|
22
|
+
#################################################################################
|
23
|
+
# #
|
24
|
+
# 一般関数 #
|
25
|
+
# #
|
26
|
+
# #
|
27
|
+
#################################################################################
|
28
|
+
# フレーム切替え=画面遷移
|
29
|
+
def change_frame(frame):
|
30
|
+
frame.tkraise()
|
31
|
+
|
32
|
+
|
33
|
+
#################################################################################
|
34
|
+
# #
|
35
|
+
# 画面生成 #
|
36
|
+
# #
|
37
|
+
# #
|
38
|
+
#################################################################################
|
39
|
+
def resource_path(relative_path):
|
40
|
+
try:
|
41
|
+
# PyInstaller creates a temp folder and stores path in _MEIPASS
|
42
|
+
base_path = sys._MEIPASS
|
43
|
+
except Exception:
|
44
|
+
base_path = os.path.abspath(".")
|
45
|
+
|
46
|
+
return os.path.join(base_path, relative_path)
|
47
|
+
|
48
|
+
|
49
|
+
def adjust_windowsize(root):
|
50
|
+
ww = root.winfo_screenwidth()
|
51
|
+
wh = root.winfo_screenheight()
|
52
|
+
|
53
|
+
lw = math.ceil(ww * 0.208)
|
54
|
+
lh = math.ceil(wh * 0.277)
|
55
|
+
|
56
|
+
root.geometry(str(lw)+"x"+str(lh)+"+"+str(int(ww/2-lw/2))+"+"+str(int(wh/2-lh/2)))
|
57
|
+
#################################################################################
|
58
|
+
# #
|
59
|
+
# フレーム生成 #
|
60
|
+
# #
|
61
|
+
# #
|
62
|
+
#################################################################################
|
63
|
+
def generate_frame(root):
|
64
|
+
#############################################################################
|
65
|
+
# #
|
66
|
+
# メインメニュー用フレーム設置 #
|
67
|
+
# #
|
68
|
+
#############################################################################
|
69
|
+
frmMain = ttk.Frame(root)
|
70
|
+
frmMain.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S)
|
71
|
+
|
12
|
-
#
|
72
|
+
# メインメニューにボタン配置
|
73
|
+
btn_SettingMenu = tk.Button(frmMain, text = "入出力定義", font=("",0,"normal","roman","normal"), command=lambda: change_frame(frmIOMenu))
|
74
|
+
btn_SettingMenu.pack(fill = tk.BOTH, expand=True)
|
75
|
+
|
76
|
+
btn_SettingMenu = tk.Button(frmMain, text = "変換定義", font=("",0,"normal","roman","normal"))
|
77
|
+
btn_SettingMenu.pack(fill = tk.BOTH, expand=True)
|
78
|
+
|
79
|
+
btn_RunMenu = tk.Button(frmMain, text = "実行メニュー", font=("",0,"normal","roman","normal"))
|
80
|
+
btn_RunMenu.pack(fill = tk.BOTH, expand=True)
|
81
|
+
btn_RunMenu.focus_set()
|
82
|
+
|
83
|
+
btn_SettingMenu = tk.Button(frmMain, text = "終了", font=("",0,"normal","roman","normal"), command=root.destroy)
|
84
|
+
btn_SettingMenu.pack(fill = tk.BOTH, expand=True)
|
85
|
+
#############################################################################
|
86
|
+
# #
|
87
|
+
# 入出力定義メニュー用フレーム設置 #
|
88
|
+
# #
|
89
|
+
#############################################################################
|
13
90
|
frmIOMenu = ttk.Frame(root)
|
14
91
|
frmIOMenu.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S)
|
15
92
|
|
@@ -40,14 +117,14 @@
|
|
40
117
|
ent_InputPath = tk.Entry(frmIOMenu, state="disabled")
|
41
118
|
ent_InputPath.grid(row=1, column=3, columnspan=7, sticky=tk.E + tk.W + tk.N + tk.S)
|
42
119
|
|
43
|
-
btn_AssignInputFile = tk.Button(frmIOMenu, text = "入力ファイル指定"
|
120
|
+
btn_AssignInputFile = tk.Button(frmIOMenu, text = "入力ファイル指定")
|
44
121
|
btn_AssignInputFile.grid(row=1, column=0, columnspan=3, sticky=tk.E + tk.W + tk.N + tk.S)
|
45
122
|
|
46
123
|
# 2 出力ファイル指定ボタン、選択ファイル格納テキストボックス配置
|
47
124
|
ent_OutputPath = tk.Entry(frmIOMenu, state="disabled")
|
48
125
|
ent_OutputPath.grid(row=2, column=3, columnspan=7, sticky=tk.E + tk.W + tk.N + tk.S)
|
49
126
|
|
50
|
-
btn_AssignOutputFile = tk.Button(frmIOMenu, text = "出力ファイル指定"
|
127
|
+
btn_AssignOutputFile = tk.Button(frmIOMenu, text = "出力ファイル指定")
|
51
128
|
btn_AssignOutputFile.grid(row=2, column=0, columnspan=3, sticky=tk.E + tk.W + tk.N + tk.S)
|
52
129
|
|
53
130
|
# 4
|
@@ -89,4 +166,62 @@
|
|
89
166
|
# 8
|
90
167
|
btn_ReturnMenu = tk.Button(frmIOMenu, text = "閉じる", command=lambda: change_frame(frmMain))
|
91
168
|
btn_ReturnMenu.grid(row=8, column=8, columnspan=2, sticky=tk.E + tk.W + tk.N + tk.S)
|
169
|
+
|
170
|
+
# 起動時メインのフレームを前面に
|
171
|
+
frmMain.tkraise()
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
if __name__ == "__main__":
|
177
|
+
# ウインドウの作成
|
178
|
+
root = tk.Tk()
|
179
|
+
|
180
|
+
#フォームサイズを実行端末から導き、ド真中に配置表示
|
181
|
+
adjust_windowsize(root)
|
182
|
+
|
183
|
+
#タイトルを指定
|
184
|
+
root.title("TkInterの勉強")
|
185
|
+
|
186
|
+
#フレーム切替え達成の上で とても重要、ルートのグリッド定義
|
187
|
+
root.grid_rowconfigure(0, weight=1)
|
188
|
+
root.grid_columnconfigure(0, weight=1)
|
189
|
+
|
190
|
+
root.grid_rowconfigure(1, weight=1)
|
191
|
+
root.grid_columnconfigure(1, weight=1)
|
192
|
+
|
193
|
+
root.grid_rowconfigure(2, weight=1)
|
194
|
+
root.grid_columnconfigure(2, weight=1)
|
195
|
+
|
196
|
+
root.grid_rowconfigure(3, weight=1)
|
197
|
+
root.grid_columnconfigure(3, weight=1)
|
198
|
+
|
199
|
+
root.grid_rowconfigure(4, weight=1)
|
200
|
+
root.grid_columnconfigure(4, weight=1)
|
201
|
+
|
202
|
+
root.grid_rowconfigure(5, weight=1)
|
203
|
+
root.grid_columnconfigure(5, weight=1)
|
204
|
+
|
205
|
+
root.grid_rowconfigure(6, weight=1)
|
206
|
+
root.grid_columnconfigure(6, weight=1)
|
207
|
+
|
208
|
+
root.grid_rowconfigure(7, weight=1)
|
209
|
+
root.grid_columnconfigure(7, weight=1)
|
210
|
+
|
211
|
+
root.grid_rowconfigure(8, weight=1)
|
212
|
+
root.grid_columnconfigure(8, weight=1)
|
213
|
+
|
214
|
+
root.grid_columnconfigure(9, weight=1)
|
215
|
+
|
216
|
+
#フォームの最大化、×ボタン操作を無効化
|
217
|
+
root.resizable(0,0)
|
218
|
+
root.protocol('WM_DELETE_WINDOW', (lambda: 'pass')())
|
219
|
+
|
220
|
+
# カーソル変更
|
221
|
+
root["cursor"] = "hand2"
|
222
|
+
|
223
|
+
generate_frame(root)
|
224
|
+
|
225
|
+
root.mainloop()
|
92
|
-
```
|
226
|
+
```
|
227
|
+

|