質問編集履歴
1
ソースコード不要部分の削除及び編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,7 +18,6 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
### 発生している問題
|
21
|
-
・エラーメッセージ
|
22
21
|
|
23
22
|
canvasに画像(jpg)が表示されない。
|
24
23
|
### 該当のソースコード
|
@@ -27,89 +26,24 @@
|
|
27
26
|
|
28
27
|
import tkinter as tk
|
29
28
|
from PIL import Image, ImageTk
|
30
|
-
import os, glob
|
31
29
|
|
32
|
-
def changeLayer(master, dirEntry, entryPosiList, entryDict):
|
33
|
-
global sub_win
|
34
|
-
global buttonDict
|
35
|
-
|
36
|
-
|
30
|
+
#画像ファイルのパス
|
37
|
-
dirPath = dirEntry.get()
|
38
|
-
|
39
|
-
#サブウィンドウが存在しなければサブウィンドウの設定
|
40
|
-
if sub_win is None or not sub_win.winfo_exists():
|
41
|
-
sub_win = tk.Toplevel(master=master)
|
42
|
-
sub_win.title("image separator")
|
43
|
-
|
31
|
+
filePath = "test.jpg"
|
44
|
-
for entryPosi in entryPosiList:
|
45
|
-
button = tk.Button(sub_win)
|
46
|
-
buttonDict[entryPosi] = button
|
47
|
-
|
48
32
|
|
49
|
-
|
33
|
+
#canvasの設定
|
50
|
-
|
34
|
+
root = tk.Tk()
|
51
|
-
|
35
|
+
root.title("input infomation")
|
52
|
-
if entryValue:
|
53
|
-
filePath = os.path.join(dirPath, entryValue)
|
54
|
-
|
36
|
+
root.geometry("400x400")
|
55
|
-
buttonDict[entryPosi]["command"] = separateImage(filePath)
|
56
|
-
buttonDict[entryPosi].pack()
|
57
37
|
|
38
|
+
canvas = tk.Canvas(root, bg="black", width=300, height=300)
|
58
|
-
|
39
|
+
canvas.pack()
|
59
|
-
|
40
|
+
img = ImageTk.PhotoImage(Image.open(filePath).convert("RGB"))
|
60
|
-
|
41
|
+
canvas.create_image(0, 0, image=img)
|
61
42
|
|
62
|
-
#canvasの設定(テストのためmfileLIst[0]])
|
63
|
-
canvas = tk.Canvas(sub_win, bg="black", width=1366, height=768)
|
64
|
-
|
43
|
+
root.mainroop()
|
65
|
-
img = ImageTk.PhotoImage(Image.open(fileList[0]).convert("RGB"))
|
66
|
-
|
44
|
+
```
|
67
45
|
|
68
|
-
#画像分類。未実装
|
69
|
-
def separateImage(filePath):
|
70
|
-
def x():
|
71
|
-
print(filePath)
|
72
|
-
return x
|
73
46
|
|
74
|
-
|
75
|
-
if __name__ == "__main__":
|
76
|
-
|
77
|
-
#メインウィンドウの設定
|
78
|
-
root = tk.Tk()
|
79
|
-
root.title("input infomation")
|
80
|
-
root.geometry("300x300")
|
81
|
-
|
82
|
-
#ボタンの配置場所及びキーのリスト
|
83
|
-
entryPosiList = ["left", "right", "top", "bottom"]
|
84
|
-
dirEntryLabel = tk.Label(root, text="dirPath")
|
85
|
-
dirEntryLabel.pack()
|
86
|
-
dirEntry = tk.Entry(root, bd=1)
|
87
|
-
dirEntry["width"] = 40
|
88
|
-
dirEntry.pack()
|
89
|
-
|
90
|
-
#入力フォーム作成
|
91
|
-
entryDict = {}
|
92
|
-
for i, entryPosi in enumerate(entryPosiList):
|
93
|
-
entryLabel = tk.Label(root, text="label"+str(i+1))
|
94
|
-
entryLabel.pack()
|
95
|
-
entry = tk.Entry(root, bd=1)
|
96
|
-
entry.pack()
|
97
|
-
entryDict[entryPosi] = entry
|
98
|
-
|
99
|
-
okButton = tk.Button()
|
100
|
-
okButton["text"] = "OK"
|
101
|
-
okButton["command"] = lambda: changeLayer(root, dirEntry, entryPosiList, entryDict)
|
102
|
-
okButton.pack()
|
103
|
-
|
104
|
-
#サブウィンドウの設定
|
105
|
-
sub_win = None
|
106
|
-
buttonDict = {}
|
107
|
-
|
108
|
-
root.mainloop()
|
109
|
-
|
110
|
-
|
111
|
-
```
|
112
|
-
|
113
47
|
### 試したこと
|
114
48
|
- 画像のRGB変換
|
115
49
|
https://teratail.com/questions/85640
|