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

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

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

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

パス

パス(path)はファイルシステムの場所(階層)を明示したものです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

1631閲覧

Python+Visual Studio Codeで画像表示に失敗する

m__gk_

総合スコア0

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

パス

パス(path)はファイルシステムの場所(階層)を明示したものです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/02/16 12:17

前提・実現したいこと

参考書をもとにpythonを勉強しているのですが、VSCodeで画像が表示できず、困っています。

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

DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning. Traceback (most recent call last): File "/Users/makot4/Desktop/python_game/Chapter6/list0604_2.py", line 7, in <module> gazou = tkinter.PhotoImage(file=root_dir + "iroha.png") File "/Users/makot4/.pyenv/versions/3.9.0/lib/python3.9/tkinter/__init__.py", line 4063, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "/Users/makot4/.pyenv/versions/3.9.0/lib/python3.9/tkinter/__init__.py", line 4008, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't open "/Users/makot4/Documents/python_game/Chapter6/list0604_2.pyiroha.png": no such file or directory

該当のソースコード

python

1import tkinter 2root = tkinter.Tk() 3root.title("初めての画像表示") 4canvas = tkinter.Canvas(root, width=400, height=600) 5canvas.pack() 6root_dir = "/Users/makot4/Documents/python_game/Chapter6/list0604_2.py" 7gazou = tkinter.PhotoImage(file=root_dir + "iroha.png") 8canvas.create_image(200, 300, image=gazou) 9root.mainloop()

試したこと

・他の質問ページを参考に絶対パスで記述しました。
・画像とプログラムは同じフォルダに入れました。

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

OS:macOS Catalina(ver:10.15.4)
Pythonのバージョン:3.9.1
テキストエディタ:Visual Studio Code(ver: 1.53.0)

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

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

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

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

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

jbpb0

2021/02/16 15:24

root_dir = "/Users/makot4/Documents/python_game/Chapter6/" では??
guest

回答1

0

gazou = tkinter.PhotoImage(file=root_dir + "/" + "iroha.png")

ではどうでしょう

投稿2021/02/16 12:20

y_waiwai

総合スコア87800

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

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

m__gk_

2021/02/16 12:27

エラーが出てしまいました、、。 DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning. Traceback (most recent call last): File "/Users/makot4/Desktop/python_game/Chapter6/list0604_2.py", line 7, in <module> gazou = tkinter.PhotoImage(file=root_dir + "/" +"iroha.png") File "/Users/makot4/.pyenv/versions/3.9.0/lib/python3.9/tkinter/__init__.py", line 4063, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "/Users/makot4/.pyenv/versions/3.9.0/lib/python3.9/tkinter/__init__.py", line 4008, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't open "/Users/makot4/Documents/python_game/Chapter6/list0604_2.py/iroha.png": no such file or directory
y_waiwai

2021/02/16 12:55

その画像ファイルのフルパスはなんでしょうか
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問