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

質問編集履歴

3

追記

2021/12/05 01:56

投稿

saya24
saya24

スコア258

title CHANGED
File without changes
body CHANGED
@@ -13,7 +13,7 @@
13
13
  現在 適用したダイアログの×ボタンが有効であるため、これを故意に操作してしまうと以下エラーを招いてしまいます。
14
14
  ![イメージ説明](b34a909fcee1d6b264a159c971e2cb92.png)
15
15
  初心者ゆえ、世間に紹介されている有用な技術の適用に苦戦しています、どなたかご見解を頂けますと幸いです。
16
-
16
+ ![menu](36acef643987306ae3c04f94986c61ab.png)![menu2](79f2b077c5ba4543dc6f0d816a3955e0.png)
17
17
  ```python
18
18
  import tkinter as tk
19
19
  import tkinter.ttk as ttk

2

追記

2021/12/05 01:56

投稿

saya24
saya24

スコア258

title CHANGED
File without changes
body CHANGED
@@ -14,4 +14,244 @@
14
14
  ![イメージ説明](b34a909fcee1d6b264a159c971e2cb92.png)
15
15
  初心者ゆえ、世間に紹介されている有用な技術の適用に苦戦しています、どなたかご見解を頂けますと幸いです。
16
16
 
17
+ ```python
18
+ import tkinter as tk
19
+ import tkinter.ttk as ttk
20
+ import math
21
+ import os
22
+ import tkinter.messagebox as tkmb
23
+ from functools import partial
24
+ import datetime
25
+ from tkinter import simpledialog
26
+
27
+ #★
28
+ class MyDialog(simpledialog.Dialog):
29
+
30
+ def body(self, master):
31
+ self.var = tk.IntVar()
32
+ val_cmd = self.master.register(self.switchButtonState)
33
+ self.a = tk.Entry(master, validate="key", validatecommand=(val_cmd, '%P'))
34
+ self.a.pack()
35
+
36
+ self.a.focus_set()
37
+
38
+ def switchButtonState(self, P):
39
+ if len(P) == 0:
40
+ self.button1['state'] = tk.DISABLED
41
+ else:
42
+ self.button1['state'] = tk.NORMAL
43
+ return True
44
+
45
+ def buttonbox(self):
46
+ box = tk.Frame(self)
47
+ self.button1 = tk.Button(box, text="OK", width=10, command=self.ok, state=tk.DISABLED)
48
+ self.button1.pack(side=tk.LEFT, padx=5, pady=5)
49
+
50
+ box.pack()
51
+
52
+ def apply(self):
53
+ self.title = self.a.get()
54
+
55
+ def answer(self):
56
+ return self.title
57
+
58
+ #★
59
+ def resource_path(relative_path):
60
+ try:
61
+ base_path = sys._MEIPASS
62
+ except Exception:
63
+ base_path = os.path.abspath(".")
64
+
65
+ return os.path.join(base_path, relative_path)
66
+
67
+ def adjust_windowsize(root):
68
+ ww = root.winfo_screenwidth()
69
+ wh = root.winfo_screenheight()
70
+
71
+ lw = math.ceil(ww * 0.3208)
72
+ lh = math.ceil(wh * 0.477)
73
+
74
+ root.geometry(str(lw)+"x"+str(lh)+"+"+str(int(ww/2-lw/2))+"+"+str(int(wh/2-lh/2)))
75
+
76
+ def info_message(msg):
77
+ tkmb.showinfo("お知らせ", msg)
78
+
79
+ def abort_message(place, msg):
80
+ return tkmb.showerror(place, msg)
81
+
82
+
83
+ #★
84
+ def generate_frame(root):
85
+
86
+ def change_frame(frame):
87
+
88
+ frame.tkraise()
89
+
90
+ style = ttk.Style()
91
+ style.theme_use('winnative')
92
+ style.map("TCombobox",selectbackground=[('!readonly','!focus','SystemWindow'),('readonly','!focus','SystemButtonFace'),],)
93
+ style.configure("TButton", font=("Arial", 16))
94
+ style.configure("TFrame", background="#FFFFCC")
95
+ style.configure("TRadiobutton", background="#FFFFCC")
96
+ style.configure("TLabel", font=("Arial", 16), anchor='', background="#FFFFCC")
97
+ style.configure("TLabelframe", background="#FFFFCC", relief="sunken")
98
+ style.configure("TLabelframe.Label", foreground="red", font=("Arial", 16), background="#FFFFCC")
99
+
100
+
101
+ def get_Answer():
102
+ Q = MyDialog(frmConvMenu)
103
+
104
+ try:
105
+
106
+ #con = db()
107
+ #connection = con.db_Connect()
108
+ #cursor = connection.cursor()
109
+
110
+ #★★★ teamikleさん回答をうけ、ダイアログ未回答でも下記条件 TRUE動作になっていることを初めて把握...(ありがとうございます)
17
- (×ボタンが押下されても OKボタンの押下にバインドされたメソッドが動作する避策でも と考えてい
111
+ #★★★ 未答をNone確認するのが正解かしれない。 いずれにしも未回答が発生させなようにるには を学ぶ
112
+ if Q.answer() != "":
113
+ data = (Q.answer(), cmbox_Tbl1.get())
114
+ sql = "UPDATE M_TABLES SET NAME=? WHERE RECNO=?"
115
+ #cursor.execute(sql, data)
116
+
117
+ info_message("A table was updated")
118
+ else:
119
+ raise Exception("coudn't get an answer")
120
+
121
+ except Exception as e:
122
+ abort_message("E510", e)
123
+ return
124
+
125
+ finally:
126
+ None
127
+ #connection.commit()
128
+ #connection.close()
129
+
130
+
131
+ #★
132
+ frmMain = ttk.Frame(root, name="frmMain")
133
+ frmMain.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S)
134
+
135
+ btn_SettingMenu = ttk.Button(frmMain, text = "入出力定義")
136
+ btn_SettingMenu.pack(fill = tk.BOTH, expand=True)
137
+ btn_SettingMenu.bind('<Return>', lambda a: change_frame(frmIOMenu))
138
+
139
+ btn_SettingMenu = ttk.Button(frmMain, text = "変換定義", command=lambda: change_frame(frmConvMenu))
140
+ btn_SettingMenu.pack(fill = tk.BOTH, expand=True)
141
+ btn_SettingMenu.bind('<Return>', lambda a: change_frame(frmConvMenu))
142
+
143
+ btn_RunMenu = ttk.Button(frmMain, text = "実行メニュー")
144
+ btn_RunMenu.pack(fill = tk.BOTH, expand=True)
145
+ btn_RunMenu.focus_set()
146
+
147
+ btn_Close = ttk.Button(frmMain, text = "終了", command=root.destroy)
148
+ btn_Close.pack(fill = tk.BOTH, expand=True)
149
+
150
+ #★
151
+ frmConvMenu = ttk.Frame(root, name="frmConvMenu")
152
+ frmConvMenu.grid_rowconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], weight=1)
153
+ frmConvMenu.grid_columnconfigure([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], weight=1, minsize=40)
154
+ frmConvMenu.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S)
155
+
156
+
157
+ lbfrm1 = ttk.LabelFrame(frmConvMenu, text="対応表登録", labelanchor="n")
158
+ lbfrm1.grid(row=1, column=0, rowspan=5, columnspan=10, sticky=tk.W + tk.E + tk.N + tk.S, padx=(10,10))
159
+
160
+
161
+ lst_tmp = [1,2,3]
162
+ cmbox_Tbl1 = ttk.Combobox(frmConvMenu, height=3, font=("Arial", 16), state="readonly", values=lst_tmp)
163
+ cmbox_Tbl1.grid(row=2, column=1, columnspan=8, sticky=tk.E + tk.W, pady=(10,0), padx=(10,10))
164
+
165
+ frmTmp = ttk.Frame(frmConvMenu, name="frmTmp")
166
+ frmTmp.grid(row=3, column=1, columnspan=8, sticky=tk.E + tk.W + tk.N + tk.S, padx=(10,10), pady=(10,0))
167
+
168
+ lab_Select = ttk.Label(frmTmp, text="種類", font=("Arial", 11))
169
+ lab_Select.grid(row=0, column=1, sticky=tk.E + tk.W)
170
+
171
+ lab_Sheet = ttk.Label(frmTmp, text="シート", font=("Arial", 11))
172
+ lab_Sheet.grid(row=0, column=3, sticky=tk.E + tk.W)
173
+
174
+ lab_FCell = ttk.Label(frmTmp, text="開始", font=("Arial", 11))
175
+ lab_FCell.grid(row=0, column=4, sticky=tk.E + tk.W)
176
+
177
+ lab_TCell = ttk.Label(frmTmp, text="終了", font=("Arial", 11))
178
+ lab_TCell.grid(row=0, column=5, sticky=tk.E + tk.W)
179
+
180
+ lab_Key = ttk.Label(frmTmp, text="キー", font=("Arial", 11))
181
+ lab_Key.grid(row=0, column=6, sticky=tk.E + tk.W)
182
+
183
+ lab_Initial = ttk.Label(frmTmp, text="初期化", font=("Arial", 11))
184
+ lab_Initial.grid(row=0, column=7, sticky=tk.E + tk.W)
185
+
186
+ global radioValue
187
+ radioValue = tk.IntVar()
188
+ rb1 = ttk.Radiobutton(frmTmp, text="Tab", variable=radioValue, value=0)
189
+ rb1.grid(row=1, column=0, sticky=tk.S)
190
+
191
+ rb2 = ttk.Radiobutton(frmTmp, text="Comma", variable=radioValue, value=1)
192
+ rb2.grid(row=1, column=1, sticky=tk.S)
193
+
194
+ rb3 = ttk.Radiobutton(frmTmp, text="Excel", variable=radioValue, value=2)
195
+ rb3.grid(row=1, column=2, sticky=tk.S)
196
+ radioValue.set(2)
197
+
198
+ btn_Select = ttk.Button(frmConvMenu, text = "選択", command=get_Answer)
199
+ btn_Select.grid(row=4, column=1, columnspan=1, sticky=tk.E + tk.W, padx=(10,0), pady=(0,10))
200
+
201
+ btn_Upload = ttk.Button(frmConvMenu, text = "Up", state=tk.DISABLED, command=lambda : importCtrl(radioValue.get()))
202
+ btn_Upload.grid(row=4, column=2, columnspan=1, sticky=tk.E + tk.W, pady=(0,10))
203
+
204
+ ent_UpPath = ttk.Entry(frmConvMenu, state=tk.DISABLED, font=("Arial", 11), width=100)
205
+ ent_UpPath.grid(row=4, column=3, columnspan=6, sticky=tk.E + tk.W, padx=(0,10), pady=(0,10))
206
+
207
+ cmbox_Sheet = ttk.Combobox(frmTmp, width=7, height=3, font=("Arial", 16), state=tk.DISABLED)
208
+ cmbox_Sheet.grid(row=1, column=3, sticky=tk.E + tk.W + tk.S)
209
+
210
+ cmbox_FCell = ttk.Combobox(frmTmp, width=3, height=3, font=("Arial", 16), state=tk.DISABLED)
211
+ cmbox_FCell.grid(row=1, column=4, sticky=tk.E + tk.W + tk.S)
212
+
213
+ cmbox_TCell = ttk.Combobox(frmTmp, width=3, height=3, font=("Arial", 16), state=tk.DISABLED)
214
+ cmbox_TCell.grid(row=1, column=5, sticky=tk.E + tk.W + tk.S)
215
+
216
+ cmbox_Key = ttk.Combobox(frmTmp, width=3, height=3, font=("Arial", 16), state=tk.DISABLED)
217
+ cmbox_Key.grid(row=1, column=6, sticky=tk.E + tk.W + tk.S)
218
+
219
+ reqinitial = tk.BooleanVar()
220
+ reqinitial.set(False)
221
+ chk_Initial = tk.Checkbutton(frmTmp, variable=reqinitial, bg="#FFFFCC", state=tk.DISABLED)
222
+ chk_Initial.grid(row=1, column=7, sticky=tk.E + tk.W + tk.S)
223
+
224
+ btn_TblM = ttk.Button(frmConvMenu, text = "個別編集", state=tk.DISABLED)
225
+ btn_TblM.grid(row=5, column=1, columnspan=8, sticky=tk.E + tk.W, padx=(10,10))
226
+
227
+ lbfrm2 = ttk.LabelFrame(frmConvMenu, text="変換定義", labelanchor="n")
228
+ 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))
229
+
230
+ cmbox_Tbl2 = ttk.Combobox(frmConvMenu, height=3, font=("Arial", 16), state="readonly")
231
+ cmbox_Tbl2.grid(row=7, column=1, columnspan=8, sticky=tk.E + tk.W, pady=(30,0), padx=(10,10))
232
+
233
+ btn_ConvM = ttk.Button(frmConvMenu, text = "変更定義の 追加 / 変更 / 削除", state=tk.DISABLED)
234
+ btn_ConvM.grid(row=8, column=1, columnspan=8, sticky=tk.E + tk.W, padx=(10,10))
235
+
236
+ btn_Inq = ttk.Button(frmConvMenu, text = "変更定義の 一覧参照", state=tk.DISABLED)
237
+ btn_Inq.grid(row=9, column=1, columnspan=8, sticky=tk.E + tk.W, padx=(10,10))
238
+
239
+ btn_ReturnMenu = ttk.Button(frmConvMenu, text = "閉じる", command=lambda: change_frame(frmMain))
240
+ btn_ReturnMenu.grid(row=11, column=8, sticky=tk.E + tk.W, padx=(0,10))
241
+
242
+ #★
243
+ frmMain.tkraise()
244
+
245
+ #★
246
+ if __name__ == "__main__":
247
+ root = tk.Tk()
248
+ adjust_windowsize(root)
249
+ root.title("TkInterの勉強")
250
+ root.grid_columnconfigure([0,1, 2, 3, 4, 5, 6, 7, 8, 9], weight=1)
251
+ root.grid_rowconfigure([0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], weight=1)
252
+ root.resizable(0,0)
253
+ root.protocol('WM_DELETE_WINDOW', (lambda: 'pass')())
254
+ root["cursor"] = "hand2"
255
+ generate_frame(root)
256
+ root.mainloop()
257
+ ```

1

誤記

2021/12/05 01:48

投稿

saya24
saya24

スコア258

title CHANGED
File without changes
body CHANGED
@@ -10,7 +10,7 @@
10
10
  の記述があります。そのためroot上で いくつかのフレームを切り替える私オリジナルのフォームは右上の×ボタンは無効化されています。
11
11
 
12
12
 
13
- 現在 適用したダイアログの×ボタンが有効であるため、これを故意に操作してしまうと以下エラーを招いてしまいます。
13
+ 現在 適用したダイアログの×ボタンが有効であるため、これを故意に操作してしまうと以下エラーを招いてしまいます。
14
14
  ![イメージ説明](b34a909fcee1d6b264a159c971e2cb92.png)
15
15
  初心者ゆえ、世間に紹介されている有用な技術の適用に苦戦しています、どなたかご見解を頂けますと幸いです。
16
16