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

回答編集履歴

1

コード中の不適切な部分を修正

2020/01/28 19:15

投稿

dodox86
dodox86

スコア9416

answer CHANGED
@@ -64,7 +64,7 @@
64
64
  # 配置済みの子ウィジェットが存在すれば、削除しておく
65
65
  children = tki.winfo_children()
66
66
  for child in children:
67
- # print("type of widget is : " + str(type(child)))
67
+ print("type of widget is : " + str(type(child)))
68
68
  if str(type(child)) == "<class 'tkinter.Radiobutton'>":
69
69
  child.destroy()
70
70
  elif str(type(child)) == "<class 'tkinter.Button'>":
@@ -94,14 +94,12 @@
94
94
  img = Image.open(fname)
95
95
  resize_img = img.resize((200, int(200 * img.size[1] / img.size[0])))
96
96
  icon = ImageTk.PhotoImage(resize_img)
97
- if icon_label is None:
98
- # ラベル未生成の場合のみ、生成する。
99
- icon_label = ttk.Label(tki, compound="top")
97
+ label = tkinter.Label(tki, compound="top")
100
- icon_label.place(x=10, y=240)
98
+ label.place(x=10, y=240)
101
99
 
102
100
  # 動的に画像とテキストをセット
103
- icon_label.configure(image=icon, text="アイコンラベル: " + fname)
101
+ label.configure(image=icon, text="アイコンラベル: " + fname)
104
- icon_label.image = icon
102
+ label.image = icon
105
103
 
106
104
  # 以前画像を使わない4択問題で使っていたコード
107
105
  # var = tkinter.StringVar()
@@ -133,5 +131,7 @@
133
131
  init_view(root)
134
132
 
135
133
  root.mainloop()
134
+
135
+
136
136
  ```
137
137
  Python 3.8 32ビット版 + Pillow 7.0.0で、Windows 10(64ビット)上にて確認しました。