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


Python Popup.withdraw方法代码示例

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


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

示例1: Menu

# 需要导入模块: from popup import Popup [as 别名]
# 或者: from popup.Popup import withdraw [as 别名]
class Menu(object):
    def __init__(self, items, x, y, alwaysHighlight = False, delegate = None, *args, **kwargs):
        # activestyle = tk.None suppresses the box in OS X and underline elsewhere.
        defaults = {'activestyle':      tk.NONE,
                    'borderwidth':      0,
                    'exportselection':  False,
                    # Approximate the colors used in OS X:
                    'selectbackground': '#0950CF',
                    'selectforeground': '#FFF',
                    # Normally tk has a weird fake-3D effect - remove that.
                    'relief':           tk.FLAT}
        self._popup   = Popup(x = x, y = y)
        self._listbox = tk.Listbox(self._popup, *args, **dict(defaults, **kwargs))
        self._listbox.pack()

        self.alwaysHighlight = alwaysHighlight
        self._priorSelection = None
        self.delegate = delegate
        self.items = items

        self._listbox.bind('<<ListboxSelect>>', self._selectionChanged)
        self._listbox.bind('<Return>',          self.selectHighlighted)
        self._listbox.bind('<Button-1>',        self.selectHighlighted)
        self._listbox.bind('<Enter>',           self._snapHighlightToMouse)
        self._listbox.bind('<Motion>',          self._snapHighlightToMouse)
        if not self.alwaysHighlight:
            self._listbox.bind('<Leave>', self.unhighlight)

    @property
    def items(self):
        return self.__items

    @items.setter
    def items(self, items):
        if items == getattr(self, '__items', None):
            return

        self._listbox['height'] = len(items)
        self._listbox['width' ] = max(len(item) for item in items)
        self.__items = items

        self._listbox.delete(0, tk.END)
        for item in items:
            self._listbox.insert(tk.END, str(item))

        if self.alwaysHighlight:
            self._listbox.selection_set(0)
            self._selectionChanged()

    @property
    def columns(self):
        return self._listbox['width']

    @columns.setter
    def columns(self, columns):
        self._listbox['width'] = columns

    def destroy(self):
        self._listbox.destroy()
        self._popup  .destroy()

    def _snapHighlightToMouse(self, event):
        ''' This is a private method. Don't touch it. '''
        self._setHighlight(self._listbox.nearest(event.y))

    def _setHighlight(self, index):
        ''' This is a private method. Don't touch it. '''
        self._listbox.selection_clear(0, tk.END)
        self._listbox.selection_set(index)
        self._selectionChanged()

    def unhighlight(self, *args):
        self._listbox.selection_clear(0, tk.END)

    def _selectionChanged(self, *args):
        ''' This is a private method. Don't touch it. '''
        currentSelection = self.items[self._listbox.curselection()[0]]
        if currentSelection == self._priorSelection:
            return
        self._priorSelection = currentSelection
        self.onHighlight(currentSelection)

    def selectHighlighted(self, *args):
        '''
        Triggers onSelect for the highlighted item.
        '''
        self.onSelect(self.items[self._listbox.curselection()[0]])

    def moveHighlight(self, amount):
        newIndex = self._listbox.curselection()[0] + amount
        newIndex = max(0, min(newIndex, len(self.items) - 1))
        self._setHighlight(newIndex)

    def hide(self):
        self._popup.withdraw()

    def show(self):
        self._popup.deiconify()

    @event
#.........这里部分代码省略.........
开发者ID:TaylorSMarks,项目名称:FinGUI,代码行数:103,代码来源:menu.py


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