0
0
実現したいこと
教科書通り 車の画像を表示させたい。
前提
記述の間違いは特にないと思います。
発生している問題・エラーメッセージ
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Endo\AppData\Local\Programs\Python\Python36-32\lib\tkinter_init_.py", line 1699, in call
return self.func(*args)
File "C:\Users\Endo\AppData\Local\Programs\Python\Python36-32\dispImage.py", line 21, in openFile
dispPhoto(fpath)
NameError: name 'dispPhoto' is not defined
該当のソースコード
import tkinter as tk
import tkinter.filedialog as fd
import PIL.Image
import PIL.ImageTk
def disPhoto(path):
# 画像を読み込む newImage = PIL.Image.open(path).resize((300,300)) # そのイメージをラベルに表示する imageData = PIL.ImageTk.PhotoImage(newImage) ImageLabel.configure(image = imageData) imageLabel.image =imageData
def openFile():
fpath = fd.askopenfilename()
if fpath: dispPhoto(fpath)
root = tk.Tk()
root.geometry("400x350")
btn = tk.Button(text="ファイルを開く",command = openFile)
imageLabel = tk.Label()
btn.pack()
imageLabel.pack()
tk.mainloop()
試したこと
Pillowのバージョン変更、教科書の参考の画像を持ってきて、無理やり開こうと
したが、開かない。
補足情報(FW/ツールのバージョンなど)
pip list (Pillow:8.4.0 / pip:20.2.2/setuptools 28.8.0)
WARNING: You are using pip version 20.2.2; however, version 21.3.1 is available.
You should consider upgrading via the 'c:\users\endo\appdata\local\programs\python\python36-32\python.exe -m pip install --upgrade pip' command.
回答2件