1
に画像を追加し、私は問題に直面してきた:のTkinterを学習するプロセスでは、ボタン
<ipython-input-30-6ad3ebb78b5b> in <module>()
7 button.grid()
8 photo=PhotoImage(file="giphy.gif")
----> 9 button.config(image=photo, compound=RIGHT)
10
11 root.mainloop()
/usr/lib/python3.5/tkinter/__init__.py in configure(self, cnf, **kw)
1331 the allowed keyword arguments call the method keys.
1332 """
-> 1333 return self._configure('configure', cnf, kw)
1334 config = configure
1335 def cget(self, key):
/usr/lib/python3.5/tkinter/__init__.py in _configure(self, cmd, cnf, kw)
1322 if isinstance(cnf, str):
1323 return self._getconfigure1(_flatten((self._w, cmd, '-'+cnf)))
-> 1324 self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
1325 # These used to be defined in Widget:
1326 def configure(self, cnf=None, **kw):
TclError: image "pyimage.." doesn't exist
:このコードは、エラーになります
from tkinter import*
from tkinter import ttk
root=Tk()
button=ttk.Button(root)
button.grid()
photo=PhotoImage(file="giphy.gif")
button.config(image=photo, compound=RIGHT)
root.mainloop()
:私はボタンに画像を追加することはできません。
なぜそうですか?それをどうやって修正することができますか?
エラーコードと一致していません。修正してください。 –
私はそれをテストし、そのコードは私のために正常に動作します。エラーを再現するコードをいくつか見せてください。 – Novel
ラベルのような他のtkinterのコンポーネントで同じエラーが発生しました。 – Korgan