我正在制作一个程序来打印图像中像素的颜色值,并引用chenlian's answer to a question here来读取RGB值。我将程序的这一部分隔离到另一个文件中进行测试。在
pic = "H://fourpxtest.png"
from tkinter import *
def getRGB(image, x, y):
value = image.get(x, y)
return tuple(map(int, value.split(" ")))
getRGB(pic, 1, 1)
是我现在的全部。运行此返回
Traceback (most recent call last):
File "H:/tzrtst.py", line 6, in <module>
getRGB(pic, 1, 1)
File "H:/tzrtst.py", line 4, in getRGB
value = image.get(x, y)
AttributeError: 'str' object has no attribute 'get'
image
到底应该是什么?我尝试过在两个位置用我的pic
变量替换单词image
,用pic
替换image
,但没什么区别。图像可以是像我这样的文件路径吗?在
image必须是PhotoImage的实例,而不是文件名http://effbot.org/tkinterbook/photoimage.htm
相关问题 更多 >
编程相关推荐