-2

我在街机模块中运行塔防游戏,但按开始后,游戏冻结并返回

Traceback (most recent call last):
  File "D:\lib\site-packages\arcade\text.py", line 278, in draw_text
    label = draw_text_cache[key]
KeyError: "05064200240left('Calibri', 'Arial')FalseFalse"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\ThisPC\Downloads\The Great Skeleton War\lab_12.py", line 2890, in <module>
    arcade.run()
  File "D:\lib\site-packages\arcade\window_commands.py", line 236, in run
    pyglet.app.run()
  File "D:\lib\site-packages\pyglet\app\__init__.py", line 107, in run
    event_loop.run()
  File "D:\lib\site-packages\pyglet\app\base.py", line 167, in run
    timeout = self.idle()
  File "D:\lib\site-packages\pyglet\app\base.py", line 243, in idle
    window.dispatch_event('on_draw')
  File "D:\lib\site-packages\pyglet\window\__init__.py", line 1333, in dispatch_event
    if EventDispatcher.dispatch_event(self, *args) != False:
  File "D:\lib\site-packages\pyglet\event.py", line 422, in dispatch_event
    self._raise_dispatch_exception(event_type, args, getattr(self, event_type), exception)
  File "D:\lib\site-packages\pyglet\event.py", line 476, in _raise_dispatch_exception
    raise exception
  File "D:\lib\site-packages\pyglet\event.py", line 415, in dispatch_event
    if getattr(self, event_type)(*args):
  File "C:\Users\ThisPC\Downloads\The Great Skeleton War\lab_12.py", line 1136, in on_draw
    arcade.render_text(globalvars.level_text, SCREEN_WIDTH - 104, SCREEN_HEIGHT - 50)
  File "D:\lib\site-packages\arcade\text.py", line 88, in render_text
    draw_text(text.text,
  File "D:\lib\site-packages\arcade\text.py", line 281, in draw_text
    image = get_text_image(text=text,
  File "D:\lib\site-packages\arcade\text.py", line 218, in get_text_image
    draw.multiline_text((image_start_x, image_start_y), text, text_color, align=align, font=font)
  File "D:\lib\site-packages\PIL\ImageDraw.py", line 446, in multiline_text
    self.text(
  File "D:\lib\site-packages\PIL\ImageDraw.py", line 365, in text
    ink = getink(fill)
  File "D:\lib\site-packages\PIL\ImageDraw.py", line 313, in getink
    ink, fill = self._getink(fill)
  File "D:\lib\site-packages\PIL\ImageDraw.py", line 112, in _getink
    ink = self.draw.draw_ink(ink)
TypeError: color must be int or tuple

我不确定为什么。它说我的 python 包是错误的,所以我也多次卸载并重新安装了 python。谁能帮我?提前谢谢。

4

2 回答 2

0

没有任何代码,这很难。但这是我的猜测。

也许它是为 Python 2 而不是 Python 3 制作的,或者模块已经更新。通常 Python 程序在虚拟环境中运行,并且有一个用于模块版本的 requirements.txt 文件。您可以激活虚拟环境、安装软件包并运行它。

问题来自错误的数据类型,变量颜色应该是 int 或 tuple 类型。在draw_text中文件“D:\lib\site-packages\arcade\text.py”的第278行,什么是type(key)

于 2020-12-22T23:42:18.757 回答
0

没有代码,很难回答。

我认为当您决定要使用的颜色时,可能是在您想在屏幕上书写的文本中,您选择了错误的格式。您可能传递了一个数组而不是具有这种形式的元组:(int, int, int)。(对于(r,g,b))如果您确实使用了一个数组,您仍然可以使用它,但是tuple(your_array)当您将它传递到您想要传递它的地方时,您必须添加该命令。

于 2021-07-10T14:45:45.807 回答