本文整理汇总了Python中nltk.draw.util.CanvasWidget.__setitem__方法的典型用法代码示例。如果您正苦于以下问题:Python CanvasWidget.__setitem__方法的具体用法?Python CanvasWidget.__setitem__怎么用?Python CanvasWidget.__setitem__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.draw.util.CanvasWidget
的用法示例。
在下文中一共展示了CanvasWidget.__setitem__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __setitem__
# 需要导入模块: from nltk.draw.util import CanvasWidget [as 别名]
# 或者: from nltk.draw.util.CanvasWidget import __setitem__ [as 别名]
def __setitem__(self, attr, value):
canvas = self.canvas()
if attr == 'roof':
self._roof = value
if self._roof:
for l in self._lines: canvas.itemconfig(l, state='hidden')
canvas.itemconfig(self._polygon, state='normal')
else:
for l in self._lines: canvas.itemconfig(l, state='normal')
canvas.itemconfig(self._polygon, state='hidden')
elif attr == 'orientation':
if value == 'horizontal': self._horizontal = 1
elif value == 'vertical': self._horizontal = 0
else:
raise ValueError('orientation must be horizontal or vertical')
elif attr == 'color':
for l in self._lines: canvas.itemconfig(l, fill=value)
canvas.itemconfig(self._polygon, outline=value)
elif isinstance(attr, tuple) and attr[0] == 'color':
# Set the color of an individual line.
l = self._lines[int(attr[1])]
canvas.itemconfig(l, fill=value)
elif attr == 'fill':
canvas.itemconfig(self._polygon, fill=value)
elif attr == 'width':
canvas.itemconfig(self._polygon, {attr:value})
for l in self._lines: canvas.itemconfig(l, {attr:value})
elif attr in ('xspace', 'yspace'):
if attr == 'xspace': self._xspace = value
elif attr == 'yspace': self._yspace = value
self.update(self._label)
elif attr == 'ordered':
self._ordered = value
else:
CanvasWidget.__setitem__(self, attr, value)
示例2: __setitem__
# 需要导入模块: from nltk.draw.util import CanvasWidget [as 别名]
# 或者: from nltk.draw.util.CanvasWidget import __setitem__ [as 别名]
def __setitem__(self, attr, value):
canvas = self.canvas()
if attr is "roof":
self._roof = value
if self._roof:
for l in self._lines:
canvas.itemconfig(l, state="hidden")
canvas.itemconfig(self._polygon, state="normal")
else:
for l in self._lines:
canvas.itemconfig(l, state="normal")
canvas.itemconfig(self._polygon, state="hidden")
elif attr == "orientation":
if value == "horizontal":
self._horizontal = 1
elif value == "vertical":
self._horizontal = 0
else:
raise ValueError("orientation must be horizontal or vertical")
elif attr == "color":
for l in self._lines:
canvas.itemconfig(l, fill=value)
canvas.itemconfig(self._polygon, outline=value)
elif isinstance(attr, tuple) and attr[0] == "color":
# Set the color of an individual line.
l = self._lines[int(attr[1])]
canvas.itemconfig(l, fill=value)
elif attr == "fill":
canvas.itemconfig(self._polygon, fill=value)
elif attr == "width":
canvas.itemconfig(self._polygon, {attr: value})
for l in self._lines:
canvas.itemconfig(l, {attr: value})
elif attr in ("xspace", "yspace"):
if attr == "xspace":
self._xspace = value
elif attr == "yspace":
self._yspace = value
self.update(self._node)
elif attr == "ordered":
self._ordered = value
else:
CanvasWidget.__setitem__(self, attr, value)