获取在 tkinter(Python) 中画布中绘制的项目的填充颜色或任何其他属性

2023-12-04

我想获取画布中绘制的项目的填充颜色或任何其他属性 在 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 method:
effbot

所以你可以使用:

color = self.canvas_1.itemcget(i, "fill")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

获取在 tkinter(Python) 中画布中绘制的项目的填充颜色或任何其他属性 的相关文章

随机推荐