当前位置: 首页>>代码示例>>Python>>正文


Python Canvas.itemcget方法代码示例

本文整理汇总了Python中tkinter.Canvas.itemcget方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.itemcget方法的具体用法?Python Canvas.itemcget怎么用?Python Canvas.itemcget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tkinter.Canvas的用法示例。


在下文中一共展示了Canvas.itemcget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TkLEDTableMixin

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import itemcget [as 别名]

#.........这里部分代码省略.........
        return self._width, self._height

    @dimensions.setter
    def dimensions(self, value):
        width, height = value
        self._remove_all_pixels()
        self._width, self._height = width, height
        self._create_pixels()

    # utility methods

    def _create_pixels(self):
        assert not self._pixels
        for y in range(self.height):
            pixels = []
            self._pixels.append(pixels)
            for x in range(self.width):
                pixel = self._canvas.create_rectangle(0,0,1,1)
                pixels.append(pixel)
        self._update_configuration()
        for y, row in enumerate(self._saved_pixels[:self.height]):
            for x, color in enumerate(row[:self.width]):
                self.set_pixel_color(x, y, color)

    def _remove_all_pixels(self):
        self._saved_pixels = [[self.get_pixel_color(x, y) for x in range(self.width)] for y in range(self.height)]
        for pixel in self._all_pixels:
            self._canvas.delete(pixel)
        self._pixels = []
        self._remove_pixel_order()

    def _remove_pixel_order(self):
        for line in self._pixel_order:
            self._canvas.delete(line)
        self._pixel_order = []

    @property
    def _all_pixels(self):
        return chain.from_iterable(self._pixels)

    def _update_configuration(self):
        for y, row in enumerate(self._pixels):
            for x, pixel in enumerate(row):
                x_cor = x * self.pixel_width
                y_cor = y * self.pixel_height
                self._canvas.coords(pixel, x_cor, y_cor,
                                           x_cor + self.pixel_width,
                                           y_cor + self.pixel_height)
                self._canvas.itemconfigure(pixel, outline = self.BORDER_COLOR,
                                                  fill = self.BACKGROUND_COLOR,
                                                  width = self.pixel_border)
        self._canvas.configure(width = self.width * self.pixel_width,
                               height = self.height * self.pixel_height)
    # pixel configuration

    @property
    def pixel_width(self):
        return self._pixel_width

    @pixel_width.setter
    def pixel_width(self, value):
        self._pixel_width = value
        self._update_configuration()
        self._remove_pixel_order()

    @property
    def pixel_height(self):
        return self._pixel_height

    @pixel_height.setter
    def pixel_height(self, value):
        self._pixel_height = value
        self._update_configuration()
        self._remove_pixel_order()

    @property
    def pixel_border(self):
        return self._pixel_border

    @pixel_border.setter
    def pixel_border(self, value):
        self._pixel_border = value
        self._update_configuration()
        
    # basic interface
    
    def set_pixel_color(self, x, y, color):
        self._canvas.itemconfigure(self._pixels[y][x], fill = color)

    def get_pixel_color(self, x, y):
        return self._canvas.itemcget(self._pixels[y][x], "fill")

    def show_pixel_order(self, coordinates):
        x_offset = (self.pixel_width + 1) / 2
        y_offset = (self.pixel_height + 1) / 2
        cor = [(x * self.pixel_width + x_offset, y * self.pixel_height + y_offset)
               for x, y in coordinates]
        for p1, p2 in zip(cor[:-1], cor[1:]):
            (x1, y1), (x2, y2) = p1, p2
            self._pixel_order.append(self._canvas.create_line(x1, y1, x2, y2, fill = self.PIXEL_ORDER_COLOR))
开发者ID:niccokunzmann,项目名称:ledtable,代码行数:104,代码来源:tkLEDTable.py


注:本文中的tkinter.Canvas.itemcget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。