質問編集履歴

1

ソースコード不要部分の削除及び編集

2018/10/15 11:43

投稿

liston
liston

スコア15

test CHANGED
File without changes
test CHANGED
@@ -38,8 +38,6 @@
38
38
 
39
39
  ### 発生している問題
40
40
 
41
- ・エラーメッセージ
42
-
43
41
 
44
42
 
45
43
  canvasに画像(jpg)が表示されない。
@@ -56,169 +54,39 @@
56
54
 
57
55
  from PIL import Image, ImageTk
58
56
 
57
+
58
+
59
+ #画像ファイルのパス
60
+
61
+ filePath = "test.jpg"
62
+
63
+
64
+
65
+ #canvasの設定
66
+
59
- import os, glob
67
+ root = tk.Tk()
68
+
69
+ root.title("input infomation")
70
+
71
+ root.geometry("400x400")
60
72
 
61
73
 
62
74
 
63
- def changeLayer(master, dirEntry, entryPosiList, entryDict):
75
+ canvas = tk.Canvas(root, bg="black", width=300, height=300)
64
76
 
65
- global sub_win
77
+ canvas.pack()
66
78
 
79
+ img = ImageTk.PhotoImage(Image.open(filePath).convert("RGB"))
80
+
67
- global buttonDict
81
+ canvas.create_image(0, 0, image=img)
68
82
 
69
83
 
70
84
 
71
- #画像があるディレクトリのパス
85
+ root.mainroop()
72
86
 
73
- dirPath = dirEntry.get()
87
+ ```
74
88
 
75
89
 
76
-
77
- #サブウィンドウが存在しなければサブウィンドウの設定
78
-
79
- if sub_win is None or not sub_win.winfo_exists():
80
-
81
- sub_win = tk.Toplevel(master=master)
82
-
83
- sub_win.title("image separator")
84
-
85
- sub_win.geometry("1024x768")
86
-
87
- for entryPosi in entryPosiList:
88
-
89
- button = tk.Button(sub_win)
90
-
91
- buttonDict[entryPosi] = button
92
-
93
-
94
-
95
-
96
-
97
- #ボタンの設定
98
-
99
- for entryPosi in entryPosiList:
100
-
101
- entryValue = entryDict[entryPosi].get()
102
-
103
- if entryValue:
104
-
105
- filePath = os.path.join(dirPath, entryValue)
106
-
107
- buttonDict[entryPosi]["text"] = entryValue
108
-
109
- buttonDict[entryPosi]["command"] = separateImage(filePath)
110
-
111
- buttonDict[entryPosi].pack()
112
-
113
-
114
-
115
- #画像のパスのリスト取得
116
-
117
- fileList = glob.glob(os.path.join(dirPath, "*.*"))
118
-
119
- print(fileList[0])
120
-
121
-
122
-
123
- #canvasの設定(テストのためmfileLIst[0]])
124
-
125
- canvas = tk.Canvas(sub_win, bg="black", width=1366, height=768)
126
-
127
- canvas.pack()
128
-
129
- img = ImageTk.PhotoImage(Image.open(fileList[0]).convert("RGB"))
130
-
131
- canvas.create_image(0, 0, image=img)
132
-
133
-
134
-
135
- #画像分類。未実装
136
-
137
- def separateImage(filePath):
138
-
139
- def x():
140
-
141
- print(filePath)
142
-
143
- return x
144
-
145
-
146
-
147
-
148
-
149
- if __name__ == "__main__":
150
-
151
-
152
-
153
- #メインウィンドウの設定
154
-
155
- root = tk.Tk()
156
-
157
- root.title("input infomation")
158
-
159
- root.geometry("300x300")
160
-
161
-
162
-
163
- #ボタンの配置場所及びキーのリスト
164
-
165
- entryPosiList = ["left", "right", "top", "bottom"]
166
-
167
- dirEntryLabel = tk.Label(root, text="dirPath")
168
-
169
- dirEntryLabel.pack()
170
-
171
- dirEntry = tk.Entry(root, bd=1)
172
-
173
- dirEntry["width"] = 40
174
-
175
- dirEntry.pack()
176
-
177
-
178
-
179
- #入力フォーム作成
180
-
181
- entryDict = {}
182
-
183
- for i, entryPosi in enumerate(entryPosiList):
184
-
185
- entryLabel = tk.Label(root, text="label"+str(i+1))
186
-
187
- entryLabel.pack()
188
-
189
- entry = tk.Entry(root, bd=1)
190
-
191
- entry.pack()
192
-
193
- entryDict[entryPosi] = entry
194
-
195
-
196
-
197
- okButton = tk.Button()
198
-
199
- okButton["text"] = "OK"
200
-
201
- okButton["command"] = lambda: changeLayer(root, dirEntry, entryPosiList, entryDict)
202
-
203
- okButton.pack()
204
-
205
-
206
-
207
- #サブウィンドウの設定
208
-
209
- sub_win = None
210
-
211
- buttonDict = {}
212
-
213
-
214
-
215
- root.mainloop()
216
-
217
-
218
-
219
-
220
-
221
- ```
222
90
 
223
91
 
224
92