繁体   English   中英

如何在tkinter中显示Entry中的值?

[英]how to display the values in Entry in tkinter?

我想知道如何在文本框中显示整数和双精度值。 因为我必须计算图像的平均值,所以我希望这些值显示在GUI的文本框中。

当我尝试使用代码时,出现错误:

AttributeError: numpy.ndarray object has no attribute set

这是因为我对ndarray使用.set() 但是没有.set()如何将值发送到文本框?

这是我的代码段:

def open():
    path=tkFileDialog.askopenfilename(filetypes=[("Image File",'.jpg')])
    blue, green, red = cv2.split(re_img)
    total = re_img.size
    B = sum(blue) / total
    G = sum(green) / total
    R = sum(red) / total
    B_mean1.append(B)
    G_mean1.append(G)
    R_mean1.append(R)

    blue.set(B_mean)

root = Tk()
blue_label = Label(app,text = 'Blue Mean')
blue_label.place(x = 850,y = 140)
blue = IntVar(None)
blue_text = Entry(app,textvariable = blue)
blue_text.place(x = 1000,y = 140)
button = Button(app, text='Select an Image',command = open)
button.pack(padx = 1, pady = 1,anchor='ne')
button.place( x = 650, y = 60)
root.mainloop()  

我不知道我的编码是否错误。 这些平均值存储在列表中。 对这个问题有什么建议吗?

谢谢你的支持!

blue是函数中的本地名称,使全局IntVar参考blue阴影。

重命名一个或另一个。

numpy.ndarray上没有任何东西叫做“ set”:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html

仔细阅读此参考资料,并弄清楚如何将B_mean应用于蓝色。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM