Skip to content

Commit 9a34fc0

Browse files
committed
bug in photoimage
1 parent 8465507 commit 9a34fc0

File tree

1 file changed

+26
-0
lines changed
  • tkinter/photoimage-pillow/bug-in-photoimage

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import tkinter as tk
2+
from PIL import ImageTk, Image
3+
4+
def show_image():
5+
6+
window = tk.Toplevel()
7+
8+
image = Image.open("image.jpg")
9+
w, h = image.size
10+
11+
photo = ImageTk.PhotoImage(image)
12+
window.photo = photo # solution for bug in PhotoImage
13+
14+
canvas = tk.Canvas(window, width=w, height=h)
15+
canvas.pack()
16+
17+
canvas.create_image(0, 0, anchor='nw', image=photo)
18+
19+
20+
root = tk.Tk()
21+
22+
b = tk.Button(root, text='IMAGE', command=show_image)
23+
b.pack()
24+
25+
root.mainloop()
26+

0 commit comments

Comments
 (0)