首页 > 解决方案 > Python 3.x turtle.Screen().register_shape() 不工作

问题描述

我一直在尝试使用 python 的海龟库创建游戏,但遇到了问题。当我尝试注册形状时,出现此错误。

Traceback (most recent call last):
  File "C:\Users\QuartzMiner6000\PycharmProjects\Test1\src\main.py", line 309, in <module>
    screen.register_shape('player.gif')
  File "C:\Users\QuartzMiner6000\AppData\Local\Programs\Python\Python36\lib\turtle.py", line 1133, in register_shape
    shape = Shape("image", self._image(name))
  File "C:\Users\QuartzMiner6000\AppData\Local\Programs\Python\Python36\lib\turtle.py", line 479, in _image
    return TK.PhotoImage(file=filename)
  File "C:\Users\QuartzMiner6000\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 3542, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Users\QuartzMiner6000\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 3498, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: encountered an unsupported criticial chunk type "mkBF"

这是我的代码

import turtle
from src.variables import *
from math import ceil

TILESIZE = 20
# the number of inventory resources per row
INVWIDTH = 8
drawing = False

# create a new 'screen' object
screen = turtle.Screen()
# calculate the width and height
width = (TILESIZE * MAPWIDTH) + max(200, INVWIDTH * 50)
num_rows = int(ceil((len(resources) / INVWIDTH)))
inventory_height = num_rows * 120 + 40
height = (TILESIZE * MAPHEIGHT) + inventory_height

screen.setup(width, height)
screen.setworldcoordinates(0, 0, width, height)
screen.bgcolor(BACKGROUNDCOLOUR)
screen.listen()

我尝试给它提供图像的完整路径并将其转换为 png,但没有任何效果。

标签: pythonpython-3.x

解决方案


推荐阅读