TL;DR Let's execute Tk () first
When I was trying to make a GUI program using tkinter, I tried to display an image on canvas, and when I wrote it, I got an error, so I tried to check the contents with ipython.
ipython
from PIL import Image, ImageTk
import tkinter as tk
img = Image.open("hoge.png ")
imgtk = ImageTk.PhotoImage(img)
Then
RuntimeError: Too early to create image
I couldn't move on
PhotoImage () cannot be used unless tk.Tk () is called first.
When I was trying to parse with ipython, it became like this because tk.Tk () in the original script was not reflected. The error that was originally in trouble was in the image, so I was confused and the discovery was delayed. On ipython, if you call root = tk.Tk () and Tk () appropriately, there is no problem after that.
Recommended Posts