python - 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,但没有任何效果。
解决方案
推荐阅读
- mapbox-android - 如何将标签(例如:1,2,3 ..)添加到android地图框中的标记图标
- c - C Programming: Segmentation fault at struct ptr. Memory alloc issue
- python - 批量生成预签名 URL boto3
- python - 如何在 Python 运行时修补函数中的一行
- spring-mvc - Spring REST Controller 没有响应 Angular 请求
- spring-integration - Spring 集成 IDE
- javascript - What is difference between "import {PROPERTY} from 'MODULE'" and "require(MODULE).PROPERTY"?
- c - 将 char 数组的元素传递到另一个位置
- javascript - onchange 属性在 javascript 中不起作用
- css - Can someone explain the difference between these css lines?