在tkinter(Python)中获取在画布上绘制的项目的填充颜色或任何其他属性 [英] Getting the fill color or any other property of a item drawn in a canvas in tkinter(Python)
本文介绍了在tkinter(Python)中获取在画布上绘制的项目的填充颜色或任何其他属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取画布中绘制的项目的填充色或其他任何属性在tkinter中.
I want to get the fill color or any other property of a item drawn in a canvas in tkinter.
def createWidgets(self):
self.canvas_1= tk.Canvas(self, bg='#FAFAFA',selectforeground='#BBDEFB');
i=self.canvas_1.create_rectangle((self.canvas_1.winfo_reqwidth()/2)+100,
(self.canvas_1.winfo_reqheight()/2)+50,
(self.canvas_1.winfo_reqwidth()/2)+150,
(self.canvas_1.winfo_reqheight()/2)+100,
fill='#FF4081',width=0)
self.canvas_1.grid();
color= #want to access the fill color of item i using some getter functions.
推荐答案
您可以使用 itemcget
方法执行此操作:
effbot
you can do this using the itemcget
method:
effbot
因此您可以使用:
color = self.canvas_1.itemcget(i, "fill")
这篇关于在tkinter(Python)中获取在画布上绘制的项目的填充颜色或任何其他属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文