简体   繁体   中英

Python 3.x turtle.Screen().register_shape() not working

I have been trying to create a game using the python's turtle library but I ran into a problem. When I try to register a shape I get this error.

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"

This is my code

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()

I have tried giving it the full path to the image and converting it to a png but nothing worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM