回答編集履歴
1
追記
answer
CHANGED
@@ -1,3 +1,39 @@
|
|
1
1
|
PhotoImageの変数をglobalにしてみてください。
|
2
2
|
|
3
|
-
[tkinterのcanvasのevent時image書き換えで画像が表示されなかったからごり押しした](https://qiita.com/iCyP/items/e76ab6f584851c39f077)
|
3
|
+
[tkinterのcanvasのevent時image書き換えで画像が表示されなかったからごり押しした](https://qiita.com/iCyP/items/e76ab6f584851c39f077)
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
【追記】
|
8
|
+
```Python
|
9
|
+
import tkinter as tk
|
10
|
+
import tkinter.filedialog as tkfiledialog
|
11
|
+
import cv2
|
12
|
+
|
13
|
+
a=20
|
14
|
+
b=650
|
15
|
+
c='#c0c0c0'
|
16
|
+
root = tk.Tk()
|
17
|
+
root.state('zoomed')
|
18
|
+
root.title("採点支援ソフト「採点切り!!")
|
19
|
+
root.configure(bg='#c0c0c0')
|
20
|
+
#root.iconbitmap(r"C:\Users\shunsuke\Pictures\test.ico")
|
21
|
+
global haruna #追加
|
22
|
+
|
23
|
+
|
24
|
+
def ni():
|
25
|
+
global haruna #追加
|
26
|
+
typ = [('pngファイル','*.png')]
|
27
|
+
dir = 'C:\pg'
|
28
|
+
fle = tkfiledialog.askopenfilename(filetypes = typ, initialdir = dir)
|
29
|
+
haruna = tk.PhotoImage(file=fle)
|
30
|
+
canvas = tk.Canvas(bg="black", width=1000, height=600)
|
31
|
+
canvas.place(x=0, y=0)
|
32
|
+
canvas.create_image(0, 0, image=haruna, anchor=tk.NW)
|
33
|
+
|
34
|
+
btn1 = tk.Button(root, text='1,答案読み込み',command=ni, bg=c, fg='black', width=15)
|
35
|
+
btn1.place(x=a, y=b)
|
36
|
+
|
37
|
+
root.mainloop()
|
38
|
+
|
39
|
+
```
|