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


Python Label.place_forget方法代码示例

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


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

示例1: Box

# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import place_forget [as 别名]
class Box(Frame): # pylint: disable=too-many-ancestors
    """Represents a single box (of 0-9) in the sudoku board."""
    _counter = 0

    def __init__(self, master):
        """Construct a Box frame with parent master.

        Args:
            master: The parent frame.
        """
        Frame.__init__(self, master, style=styles.BOX_FRAME)
        self.position = (0, 0)
        self.binding_tag = 'BoxFrame' + str(Box._counter)
        self.number_text = StringVar(self, '')
        Box._counter += 1

        self.borders = dict()
        for edge in 'nesw':
            self.borders[edge] = Border(self, edge)

        self.inner_frame = Frame(self, width=30, height=30, style=styles.BOX_FRAME)
        self.pencil_marks = _build_3x3_grid(self.inner_frame, Pencil)

        self.label = Label(self.inner_frame, textvariable=self.number_text, style=styles.NUMBER_LABEL)

        _tag_widget(self, self.binding_tag)
        _tag_widget(self.inner_frame, self.binding_tag)
        _tag_widget(self.label, self.binding_tag)
        for mark in self.pencil_marks:
            _tag_widget(mark, self.binding_tag)
            _tag_widget(mark.label, self.binding_tag)

    def place_at_position(self, position):
        """Places this frame in its parent at the given position.

        Args:
            position: Tuple of (x, y) for the position to place at.
            parent_position: Tuple of (x, y) for the position the parent is in relative to the grandparent.
        """
        row = position[0]
        col = position[1]

        parent_position = self.master.position  # master "ought to be" SubGrid
        self.position = (parent_position[0] * 3 + row, parent_position[1] * 3 + col)

        padx = (0, _BOX_PADDING) if col < 2 else 0
        pady = (0, _BOX_PADDING) if row < 2 else 0
        self.grid(row=row, column=col, padx=padx, pady=pady, sticky='nesw')

        self.inner_frame.pack(padx=_BORDER_WIDTH, pady=_BORDER_WIDTH, expand=True)
        self.number = 0

    @property
    def number(self):
        """The number the box contains. Setting this value may change the box's style."""
        try:
            return int(self.number_text.get())
        except ValueError:
            return 0

    @number.setter
    def number(self, value):
        for pencil_mark in self.pencil_marks:
            pencil_mark.grid_forget()
        self['style'] = styles.BOX_FRAME
        self.inner_frame['style'] = styles.BOX_FRAME
        self.label['style'] = styles.NUMBER_LABEL

        self.label.place(relx=0.5, rely=0.5, anchor='center')
        self.number_text.set(str(value or ' ')[0])

    @property
    def given(self):
        """The given value for this box. Setting this value may change the box's style."""
        if self['style'] != styles.GIVEN_FRAME:
            return 0
        else:
            return self.number

    @given.setter
    def given(self, value):
        for pencil_mark in self.pencil_marks:
            pencil_mark.grid_forget()
        self['style'] = styles.GIVEN_FRAME
        self.inner_frame['style'] = styles.GIVEN_FRAME
        self.label['style'] = styles.GIVEN_LABEL

        self.label.place(relx=0.5, rely=0.5, anchor='center')
        self.number_text.set(str(value or ' ')[0])

    def set_pencils(self, values=0b111111111):
        """Sets the box's pencils to showing.

        Args:
            values: Which pencil marks to display.
                Bit0 set means display the '1' pencil mark, bit1 set means display the '2' pencil mark, etc.
        """
        self.label.place_forget()
        self['style'] = styles.BOX_FRAME
        self.inner_frame['style'] = styles.BOX_FRAME
#.........这里部分代码省略.........
开发者ID:Tinister,项目名称:SudokuSolver,代码行数:103,代码来源:frames.py


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