首页 > 解决方案 > 如何在海龟模块python的写入命令中使用整数

问题描述

我想在写命令中使用整数。

import turtle
t=turtle.Turtle()
a=0
b=0
t.write(a,':',b)

当我运行此代码时,它会显示以下错误:

Traceback (most recent call last):
  File "C:\Users\Drukker\AppData\Local\Programs\Python\Python39\Among_us.py", line 5, in <module>
    t.write(a,':',b)
  File "C:\Users\Drukker\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 3432, in write
    end = self._write(str(arg), align.lower(), font)
AttributeError: 'int' object has no attribute 'lower'

有谁知道解决这个问题?谢谢

标签: pythonintegerturtle-graphicspython-turtle

解决方案


您应该使用一个字符串作为参数。尝试;

t.write(str(a)+':'+str(b))

推荐阅读