运行代码返回“color must int or tuple”

问题描述

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

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,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。 谁能帮我? 顺便说一句,提前致谢。

解决方法

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

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

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

,

没有代码,很难回答。

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