【问题标题】:Pygame pygame.error: Error reading from ICOPygame pygame.error:从 ICO 读取错误
【发布时间】:2018-03-01 20:47:24
【问题描述】:

我有一个使用 pygame 的项目,一开始,它使用 pygame 来更改标题和图标以及设置屏幕,但由于某种原因,当我尝试设置图标时,我一直收到同样的错误,我用 bmp、jpg、ico 和 png 尝试过这个。都给出相同的错误:

Traceback (most recent call last):
  File "D:\Programming\Python\Python 3.6.2\RoboCart LED Controller\RC_CTRL11.py", line 87, in <module>
    main()
  File "D:\Programming\Python\Python 3.6.2\RoboCart LED Controller\RC_CTRL11.py", line 7, in main
    screen = initDisp()
  File "D:\Programming\Python\Python 3.6.2\RoboCart LED Controller\RC_CTRL11.py", line 80, in initDisp
    icon = pygame.image.load('progIcon.ico')
pygame.error: Error reading from ICO

我正在使用的产生错误的代码可以在这个函数中找到:

def initDisp():
    # Init pygame to the screen resolution
    global RESOLUTION
    pygame.init()
    screen = pygame.display.set_mode(RESOLUTION)
    pygame.display.set_caption("ROBO_CTRL11")
    icon = pygame.image.load('progIcon.ico')
    pygame.display.set_icon(icon)
    return screen

这可能是一个简单的答案的愚蠢问题,我希望这是因为我在网上找不到太多。附言我尝试的所有图片都在python文件的当前目录中。

P.P.S:针对该问题的单元测试如下:

import pygame

def main():
    screen = initDisp()

def initDisp():
    # Init pygame to the screen resolution
    RESOLUTION = (420, 380)
    pygame.init()
    screen = pygame.display.set_mode(RESOLUTION)
    pygame.display.set_caption("ROBO_CTRL11")
    icon = pygame.image.load('progIcon.ico')
    pygame.display.set_icon(icon)
    return screen

if __name__ == '__main__':
    main()

附件是我尝试使用的照片,所有格式。 Icon Photos

【问题讨论】:

  • .ico 格式似乎是not supported,但它应该适用于其他格式。使用 jpg 或 png 再试一次,并仔细检查名称和文件扩展名是否拼写正确。
  • 我已经仔细检查了文件名和扩展名,它给了我相同的结果
  • 你能张贴minimal, runnable example 和图片吗?

标签: python image compiler-errors pygame icons


【解决方案1】:

我遇到了同样的问题,我的解决方案是添加路径,不管它与程序在同一个目录中(路径中的 \ 而不是 \)。

像这样-

icon = pygame.image.load("C:\\Users\\User\\DesktopAppIcon.png") pygame.display.set_icon(icon)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多