質問編集履歴

3

やってみたことの追加

2018/10/10 07:03

投稿

jun_endo
jun_endo

スコア56

test CHANGED
File without changes
test CHANGED
@@ -337,3 +337,57 @@
337
337
 
338
338
 
339
339
  ```
340
+
341
+
342
+
343
+ #試してみたこと
344
+
345
+ タグ付けして、一度deleteしてから、
346
+
347
+ 再度、create_imageをしてみたが、
348
+
349
+ 変更されませんでした。**(厳密には、デフォの画像が無くなり、何も表示されなくなった)**
350
+
351
+
352
+
353
+ #変更箇所
354
+
355
+ ```python
356
+
357
+ def button1_clicked():内のcanvas_1部分を
358
+
359
+
360
+
361
+ canvas_1.delete("bef")#追加
362
+
363
+ canvas_1.create_image(
364
+
365
+ 0,
366
+
367
+ 0,
368
+
369
+ image=img,
370
+
371
+ anchor=tk.NW,
372
+
373
+ tag="bef"#追加
374
+
375
+ )
376
+
377
+ if __name__ == '__main__':内のcanvas部分を
378
+
379
+ canvas_1.create_image(
380
+
381
+ 0,
382
+
383
+ 0,
384
+
385
+ image=img2,
386
+
387
+ anchor=tk.NW,
388
+
389
+ tag="bef"#追加
390
+
391
+ )
392
+
393
+ ```

2

誤字修正

2018/10/10 07:03

投稿

jun_endo
jun_endo

スコア56

test CHANGED
File without changes
test CHANGED
@@ -100,15 +100,17 @@
100
100
 
101
101
  img = ImageTk.PhotoImage(image)
102
102
 
103
- canvas.itemconfig(
103
+ on_camvas = canvas_1.create_image(
104
-
104
+
105
- on_canvas,
105
+ 0,
106
+
106
-
107
+ 0,
108
+
107
- image=img
109
+ image=img,
110
+
108
-
111
+ anchor=tk.NW
112
+
109
- )
113
+ )
110
-
111
-
112
114
 
113
115
  # button2クリック時の処理
114
116
 

1

プログラムの修正

2018/10/10 06:57

投稿

jun_endo
jun_endo

スコア56

test CHANGED
File without changes
test CHANGED
@@ -100,13 +100,95 @@
100
100
 
101
101
  img = ImageTk.PhotoImage(image)
102
102
 
103
+ canvas.itemconfig(
104
+
105
+ on_canvas,
106
+
107
+ image=img
108
+
109
+ )
110
+
111
+
112
+
113
+ # button2クリック時の処理
114
+
115
+ def button2_clicked():
116
+
117
+ #省略
118
+
119
+
120
+
121
+
122
+
123
+ if __name__ == '__main__':
124
+
125
+ global on_canvas
126
+
127
+ # rootの作成
128
+
129
+ root = Tk()
130
+
131
+ root.geometry("1000x400")
132
+
133
+ root.title('machine learning')
134
+
135
+ root.resizable(False, False)
136
+
137
+
138
+
139
+ # Frame1の作成
140
+
141
+ frame1 = tk.Frame(root, width=400, height=70)
142
+
143
+ frame1.place(x=0, y=0)
144
+
145
+
146
+
147
+ # Frame2の作成
148
+
149
+ frame2 = tk.Frame(root, width=270, height=100)
150
+
151
+ frame2.place(x=0, y=30)
152
+
153
+
154
+
155
+ # Frame3の作成
156
+
157
+ frame3 = tk.Frame(root, width=620, height=362)
158
+
159
+ frame3.place(x=369, y=0)
160
+
161
+
162
+
163
+ canvas_1 = tk.Canvas(
164
+
165
+ frame3,
166
+
167
+ width=300,
168
+
169
+ height=300,
170
+
171
+ relief=tk.RIDGE,
172
+
173
+ bd=3,
174
+
175
+ bg="white"
176
+
177
+ )
178
+
179
+ canvas_1.place(x=1, y=50)
180
+
181
+ image2 = Image.open("sideface.jpg")
182
+
183
+ img2 = ImageTk.PhotoImage(image2)
184
+
103
185
  on_canvas = canvas_1.create_image(
104
186
 
105
187
  0,
106
188
 
107
189
  0,
108
190
 
109
- image=img,
191
+ image=img2,
110
192
 
111
193
  anchor=tk.NW
112
194
 
@@ -114,57 +196,115 @@
114
196
 
115
197
 
116
198
 
117
- # button2クリック時処理
118
-
119
- def button2_clicked():
120
-
121
- #省略
122
-
123
-
124
-
125
-
126
-
127
- if __name__ == '__main__':
128
-
129
- global on_canvas
130
-
131
- # rootの作成
132
-
133
- root = Tk()
134
-
135
- root.geometry("1000x400")
136
-
137
- root.title('machine learning')
138
-
139
- root.resizable(False, False)
140
-
141
-
142
-
143
- # Frame1の作成
144
-
145
- frame1 = tk.Frame(root, width=400, height=70)
146
-
147
- frame1.place(x=0, y=0)
148
-
149
-
150
-
151
- # Frame2の作成
152
-
153
- frame2 = tk.Frame(root, width=270, height=100)
154
-
155
- frame2.place(x=0, y=30)
156
-
157
-
158
-
159
- # Frame3の作成
160
-
161
- frame3 = tk.Frame(root, width=620, height=362)
162
-
163
- frame3.place(x=369, y=0)
164
-
165
-
166
-
167
- canvas_1 = tk.Canvas(
199
+ #参照ボタン作成
200
+
201
+ button1 = tk.Button(
202
+
203
+ frame1,
204
+
205
+ text=u'[参照]',
206
+
207
+ command=button1_clicked,
208
+
209
+ width=10
210
+
211
+ )
212
+
213
+ button1.place(x=283, y=35)
214
+
215
+ # 「ファイル」ラベルの作成
216
+
217
+ s = StringVar()
218
+
219
+ s.set('ファイル>>')
220
+
221
+ label1 = tk.Label(frame1, textvariable=s)
222
+
223
+ label1.place(x=0, y=5)
224
+
225
+
226
+
227
+ # 参照ファイルパス表示ラベルの作成
228
+
229
+ file1 = StringVar()
230
+
231
+ file1_entry = tk.Entry(
232
+
233
+ frame1,
234
+
235
+ textvariable=file1,
236
+
237
+ width=50
238
+
239
+ )
240
+
241
+ file1_entry.place(x=57, y=7)
242
+
243
+
244
+
245
+
246
+
247
+ # Startボタンの作成
248
+
249
+ button2 = tk.Button(
250
+
251
+ frame2,
252
+
253
+ text='[Start]',
254
+
255
+ command=button2_clicked,
256
+
257
+ width=10
258
+
259
+ )
260
+
261
+ button2.place(x=10, y=6)
262
+
263
+
264
+
265
+ # Cancelボタンの作成
266
+
267
+ button3 = tk.Button(
268
+
269
+ frame2,
270
+
271
+ text='[Cancel]',
272
+
273
+ command=quit,
274
+
275
+ width=10
276
+
277
+ )
278
+
279
+ button3.place(x=100, y=6)
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+ lb = StringVar()
288
+
289
+ lb.set("Before")
290
+
291
+ label_before = tk.Label(frame3, textvariable=lb, font=30)
292
+
293
+ label_before.place(x=0, y=0)
294
+
295
+
296
+
297
+ la = StringVar()
298
+
299
+ la.set("After")
300
+
301
+ label_after = tk.Label(frame3, textvariable=la, font=30)
302
+
303
+ label_after.place(x=308, y=0)
304
+
305
+
306
+
307
+ canvas_2 = tk.Canvas(
168
308
 
169
309
  frame3,
170
310
 
@@ -180,150 +320,6 @@
180
320
 
181
321
  )
182
322
 
183
- canvas_1.place(x=1, y=50)
184
-
185
- image2 = Image.open("sideface.jpg")
186
-
187
- img2 = ImageTk.PhotoImage(image2)
188
-
189
- on_canvas = canvas_1.create_image(
190
-
191
- 0,
192
-
193
- 0,
194
-
195
- image=img2,
196
-
197
- anchor=tk.NW
198
-
199
- )
200
-
201
-
202
-
203
- #参照ボタンの作成
204
-
205
- button1 = tk.Button(
206
-
207
- frame1,
208
-
209
- text=u'[参照]',
210
-
211
- command=button1_clicked,
212
-
213
- width=10
214
-
215
- )
216
-
217
- button1.place(x=283, y=35)
218
-
219
- # 「ファイル」ラベルの作成
220
-
221
- s = StringVar()
222
-
223
- s.set('ファイル>>')
224
-
225
- label1 = tk.Label(frame1, textvariable=s)
226
-
227
- label1.place(x=0, y=5)
228
-
229
-
230
-
231
- # 参照ファイルパス表示ラベルの作成
232
-
233
- file1 = StringVar()
234
-
235
- file1_entry = tk.Entry(
236
-
237
- frame1,
238
-
239
- textvariable=file1,
240
-
241
- width=50
242
-
243
- )
244
-
245
- file1_entry.place(x=57, y=7)
246
-
247
-
248
-
249
-
250
-
251
- # Startボタンの作成
252
-
253
- button2 = tk.Button(
254
-
255
- frame2,
256
-
257
- text='[Start]',
258
-
259
- command=button2_clicked,
260
-
261
- width=10
262
-
263
- )
264
-
265
- button2.place(x=10, y=6)
266
-
267
-
268
-
269
- # Cancelボタンの作成
270
-
271
- button3 = tk.Button(
272
-
273
- frame2,
274
-
275
- text='[Cancel]',
276
-
277
- command=quit,
278
-
279
- width=10
280
-
281
- )
282
-
283
- button3.place(x=100, y=6)
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
- lb = StringVar()
292
-
293
- lb.set("Before")
294
-
295
- label_before = tk.Label(frame3, textvariable=lb, font=30)
296
-
297
- label_before.place(x=0, y=0)
298
-
299
-
300
-
301
- la = StringVar()
302
-
303
- la.set("After")
304
-
305
- label_after = tk.Label(frame3, textvariable=la, font=30)
306
-
307
- label_after.place(x=308, y=0)
308
-
309
-
310
-
311
- canvas_2 = tk.Canvas(
312
-
313
- frame3,
314
-
315
- width=300,
316
-
317
- height=300,
318
-
319
- relief=tk.RIDGE,
320
-
321
- bd=3,
322
-
323
- bg="white"
324
-
325
- )
326
-
327
323
 
328
324
 
329
325
  canvas_2.place(x=308, y=50)