質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%

Q&A

解決済

1回答

449閲覧

Pillowのエラー

退会済みユーザー

退会済みユーザー

総合スコア0

0グッド

0クリップ

投稿2023/01/12 10:12

編集2023/01/12 10:29

前提・実現したいこと

Pythonで写真を表示するアプリを作ろうとしたところ次のエラーが発生しました。どうすれば正しく動作しますか?

発生している問題・エラーメッセージ

Traceback (most recent call last): File "/home/fuyofuyopiroq/photo/index.py", line 22, in <module> label.pack() TypeError: pack_configure() missing 1 required positional argument: 'self'

該当のソースコード

Python

1import tkinter as tk 2import tkinter.filedialog as filelog 3import PIL.Image 4import PIL.ImageTk 5root=tk.Tk() 6root.geometry("500x500") 7root.configure(bg="black") 8def openphoto(path): 9 newimage=PIL.Image.open(path).resize((350,350)) 10 imagedata=PIL.ImageTk.PhotoImage(newimage) 11 label.configure(image=imagedata) 12 label.image=imagedata 13def openfile(): 14 fpath=filelog.askopenfilename 15 if fpath: 16 openphoto(fpath) 17 18label=tk.Label 19button=tk.Button(text="Open file") 20button["command"]=openfile 21button.pack() 22label.pack() 23tk.mainloop()

試したこと

20行目を

Python

1button["command"]=openfile()

に変えると、次のエラーが表示されました。

Traceback (most recent call last): File "/home/xxx/.local/lib/python3.9/site-packages/PIL/Image.py", line 3231, in open fp.seek(0) AttributeError: 'function' object has no attribute 'seek' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/xxx/photo/index.py", line 20, in <module> button["command"]=openfile() File "/home/xxx/photo/index.py", line 16, in openfile openphoto(fpath) File "/home/xxx/photo/index.py", line 9, in openphoto newimage=PIL.Image.open(path).resize((350,350))#open file and resize file(350x350) File "/home/xxx/.local/lib/python3.9/site-packages/PIL/Image.py", line 3233, in open fp = io.BytesIO(fp.read()) AttributeError: 'function' object has no attribute 'read'

補足情報(FW/ツールのバージョンなど)

Python3.9
Debian11.5(Chromebook Crostini)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

melian

2023/01/12 10:41

label=tk.Label => label=tk.Label() fpath=filelog.askopenfilename => fpath=filelog.askopenfilename()
guest

回答1

0

ベストアンサー

質問へのコメントを参照

投稿2023/01/25 10:44

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問