回答編集履歴
3
誤った回答をしたため非表示にした.
test
CHANGED
@@ -1,61 +1,3 @@
|
|
1
|
-
|
1
|
+
誤ったソースコードを貼り付けたため,混乱を招かぬように削除しました.
|
2
2
|
|
3
|
-
[tkinter canvas image is not displayed in class
|
4
|
-
|
5
|
-
](https://stackoverflow.com/questions/16846469/tkinter-canvas-image-is-not-displayed-in-class)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
このサイトをもとにプログラムを書き換えたらできました.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
```Python
|
14
|
-
|
15
|
-
import tkinter as tk
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
class App:
|
20
|
-
|
21
|
-
def __init__(self, win):
|
22
|
-
|
23
|
-
self.win = win
|
24
|
-
|
25
|
-
self.win.geometry("500x500")
|
26
|
-
|
27
|
-
self.view_create()
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def view_create(self):
|
32
|
-
|
33
|
-
self.win.rowconfigure(0, weight=1)
|
34
|
-
|
35
|
-
self.win.columnconfigure(0, weight=1)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
self.imgfile = "c:/Users/ユーザ名/Desktop/test/test.png"
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
self.canvas = tk.Canvas(self.win)
|
44
|
-
|
45
|
-
self.canvas.grid(row=0, column=0, sticky="nsew")
|
46
|
-
|
47
|
-
self.canvas.background = tk.PhotoImage(self.imgfile)
|
48
|
-
|
49
|
-
self.canvas.create_image(0, 0, image=self.canvas.background, anchor=tk.NW)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
if __name__ == "__main__":
|
54
|
-
|
55
|
-
win = tk.Tk()
|
56
|
-
|
57
|
-
|
3
|
+
申し訳ないです.
|
58
|
-
|
59
|
-
win.mainloop()
|
60
|
-
|
61
|
-
```
|
2
コピペミス
test
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
self.canvas.grid(row=0, column=0, sticky="nsew")
|
46
46
|
|
47
|
-
self.canvas.background = tk.PhotoImage(
|
47
|
+
self.canvas.background = tk.PhotoImage(self.imgfile)
|
48
48
|
|
49
49
|
self.canvas.create_image(0, 0, image=self.canvas.background, anchor=tk.NW)
|
50
50
|
|
1
コメントアウト取り消し
test
CHANGED
@@ -46,7 +46,7 @@
|
|
46
46
|
|
47
47
|
self.canvas.background = tk.PhotoImage(file=self.imgfile)
|
48
48
|
|
49
|
-
|
49
|
+
self.canvas.create_image(0, 0, image=self.canvas.background, anchor=tk.NW)
|
50
50
|
|
51
51
|
|
52
52
|
|