python-3.x 为什么我不能用stddraw来画图片?

ztmd8pv5  于 2023-08-08  发布在  Python
关注(0)|答案(1)|浏览(110)

我尝试使用stddraw简单地绘制一张图片,代码如下:

def main():
    if len(sys.argv) <= 1:
        stdio.writeln("ERROR: Too few Arguments")
    else:
        pic = sys.argv[1]

        stddraw.picture(pic)

        stddraw.show()

if __name__ == "__main__": main()

字符串
但每次我运行它与输入像“picture.jpg”我得到这个错误:

AttributeError: 'str' object has no attribute 'width'


为什么它把它作为一个字符串来处理,我需要做什么才能让它工作?

9jyewag0

9jyewag01#

from introcs import Picture, stddraw

def main():
    if len(sys.argv) <= 1:
        stdio.writeln("ERROR: Too few Arguments")
    else:
        pic_file = sys.argv[1]
        pic = Picture(pic_file)  # Create a Picture object

        stddraw.picture(pic)

        stddraw.show()

if __name__ == "__main__":
    main()

字符串

相关问题