回答編集履歴
2
補足
answer
CHANGED
@@ -13,8 +13,14 @@
|
|
13
13
|
canvas.photo = tmp_img
|
14
14
|
```
|
15
15
|
参考情報:[The Tkinter PhotoImage Class](http://effbot.org/tkinterbook/photoimage.htm)
|
16
|
+
> Note: When a PhotoImage object is garbage-collected by Python (e.g. when you return from a function which stored an image in a local variable), the image is cleared even if it’s being displayed by a Tkinter widget.
|
16
17
|
|
18
|
+
> To avoid this, the program must keep an extra reference to the image object. A simple way to do this is to assign the image to a widget attribute, like this:
|
17
19
|
|
20
|
+
> label = Label(image=photo)
|
21
|
+
> label.image = photo # keep a reference!
|
22
|
+
> label.pack()
|
23
|
+
|
18
24
|
動作テストしていませんが、こんな感じでしょうか。
|
19
25
|
```Python
|
20
26
|
# -*- coding: utf8 -*-
|
1
追記
answer
CHANGED
@@ -1,13 +1,20 @@
|
|
1
|
+
> _tkinter.TclError: unknown option "-file"
|
2
|
+
|
3
|
+
グーグル翻訳
|
4
|
+
_tkinter.TclError:不明なオプション "-file"
|
5
|
+
|
1
6
|
```diff
|
2
7
|
-canvas.itemconfigure(c0,file = tmp_img)#コメントアウトしないとエラーが出て画面が出てこない
|
3
8
|
+canvas.create_image(180, 150, image = tmp_img)
|
4
9
|
```
|
5
10
|
|
6
|
-
あとcanvas側に参照を持たないとGC(GarbageCollection)で画像が消えます。
|
11
|
+
あと`canvas`側に`PhotoImage`の参照を持たないとGC(`GarbageCollection`)で画像が消えます。
|
7
12
|
```Python
|
8
13
|
canvas.photo = tmp_img
|
9
14
|
```
|
15
|
+
参考情報:[The Tkinter PhotoImage Class](http://effbot.org/tkinterbook/photoimage.htm)
|
10
16
|
|
17
|
+
|
11
18
|
動作テストしていませんが、こんな感じでしょうか。
|
12
19
|
```Python
|
13
20
|
# -*- coding: utf8 -*-
|
@@ -25,7 +32,7 @@
|
|
25
32
|
# 写真更新
|
26
33
|
# 30秒毎に写真を撮影しcanvasの写真を更新させたい
|
27
34
|
def change_flag():
|
28
|
-
# ※Popenはプロセス標準入出力をcloseしないとハンドルリークするかもです。
|
35
|
+
# ※Popenはプロセスの標準入出力をcloseしないとハンドルリークするかもです。
|
29
36
|
# もし長時間(5時間)動作するなら、subprocess.callの方を使ってくださいな。
|
30
37
|
subprocess.Popen(take_img.split())
|
31
38
|
canvas.photo = PhotoImage(file = '/home/pi/SUSHSS/img/data/tmp.png')
|