为什么如果我通过VS Code而不是PyCharm运行程序,图像不可用?

huangapple go评论58阅读模式
英文:

Why are the Images not available if I run the program through VS Code instead of PyCharm?

问题

Used Images don't show up while I use VS Code, but everywhere else the Images are there.

我在使用VS Code时,已使用的图片不显示,但在其他地方都显示出来。

I wrote my first Program in PyCharm and if I run the program on PyCharm the Images used will show up as they should. I drag and dropped the same .py file into VS Code, picked my Python interpreter and there aren't any problems. But the implented pictures only show up if I run the program with PyCharm or double-click the .py in the folder.

我在PyCharm中编写了我的第一个程序,如果我在PyCharm上运行程序,所使用的图片会正常显示。我将相同的.py文件拖放到了VS Code中,选择了Python解释器,没有出现任何问题。但是,只有当我在PyCharm中运行程序或在文件夹中双击.py文件时,实现的图片才会显示出来。

While the .py file is opened in VS Code and i hover over the file in the upper bar, the shown directory is the one where I drag and dropped it from into VS Code, in this same folder are also the used Images.

当.py文件在VS Code中打开时,当我将鼠标悬停在上方栏中的文件上时,显示的目录是我从中拖放到VS Code中的目录,这个目录中也包含了使用的图片。

Why does VS Code don't show the Images and how can I fix this? It will run the program and I can also interact normally with the program, beside the missing Pictures/Icons.

为什么VS Code不显示图片,我该如何修复这个问题?程序会运行,我也可以正常与程序交互,除了缺少的图片/图标。

I used PyQt5 for this program and this is the Code for the Frame which is in the program and the picture I implemented in this Frame:

我在这个程序中使用了PyQt5,以下是程序中的框架代码以及我在此框架中实现的图片:

        self.frame = QtWidgets.QFrame(Dialog)
        self.frame.setGeometry(QtCore.QRect(35, 170, 257, 171))
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.label = QtWidgets.QLabel(self.frame)
        self.label.setGeometry(QtCore.QRect(0, 0, 257, 171))
        self.label.setScaledContents(True)
        self.label.setPixmap(QtGui.QPixmap("essen.png"))
        self.label.setObjectName("label")
英文:

Used Images don't show up while I use VS Code, but everywhere else the Images are there.

I wrote my first Program in PyCharm and if I run the program on PyCharm the Images used will show up as they should. I drag and dropped the same .py file into VS Code, picked my Python interpreter and there aren't any problems. But the implented pictures only show up if I run the program with PyCharm or double-click the .py in the folder.

While the .py file is opened in VS Code and i hover over the file in the upper bar, the shown directory is the one where I drag and dropped it from into VS Code, in this same folder are also the used Images.

Why does VS Code don't show the Images and how can I fix this? It will run the program and I can also interact normally with the program, beside the missing Pictures/Icons.

I used PyQt5 for this program and this is the Code for the Frame which is in the program and the picture I implemented in this Frame:

```python
        self.frame = QtWidgets.QFrame(Dialog)
        self.frame.setGeometry(QtCore.QRect(35, 170, 257, 171))
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.label = QtWidgets.QLabel(self.frame)
        self.label.setGeometry(QtCore.QRect(0, 0, 257, 171))
        self.label.setScaledContents(True)
        self.label.setPixmap(QtGui.QPixmap("essen.png"))
        self.label.setObjectName("label")
```

答案1

得分: 0

Vscode将当前打开的文件夹作为工作区,最好将代码脚本和图片文件放在同一个目录中。

或者,您可以使用绝对路径来指示代码中的图像位置。

英文:

Vscode takes the currently opened folder as the workspace, you'd better put your code script and your picture file in the same directory.

Or you can use an absolute path to indicate the image location in the code.

huangapple
  • 本文由 发表于 2023年5月21日 02:02:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76296665.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定