前提
PythonのTkinterというライブラリを使用して画像を読み込んで表示するコードを書きました。しかし、エラーが出て読み込むことができません。
実現したいこと
画像を読み込んで表示したい。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "c:\Python\chap3\chap3.py", line 9, in <module> img=tkinter.PhotoImage(file='chika.png') File "C:\Users\patpw\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4093, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "C:\Users\patpw\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4038, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't open "chika.png": no such file or directory
該当のソースコード
Python
1import tkinter 2 3root = tkinter.Tk() 4root.title("aiueo") 5root.minsize(800,600) 6 7#キャンパス作成 8canvas = tkinter.Canvas(bg="black",width=800,height=600) 9canvas.place(x=0,y=0 10 11#画像読み込み 12img=tkinter.PhotoImage(file='chika.png') 13canvas.create_image(0,0,image=img) 14 15root.mainloop()
試したこと
この.pyファイルと同じディレクトリに画像を配置して再試行しましたが同様のエラーが出ます。
補足情報(FW/ツールのバージョンなど)

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/01 11:21
2022/09/01 15:01