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


Python TK_ROOT.winfo_rooty方法代码示例

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


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

示例1: _show

# 需要导入模块: from tk_tools import TK_ROOT [as 别名]
# 或者: from tk_tools.TK_ROOT import winfo_rooty [as 别名]
def _show(widget: tk.Misc, mouse_x, mouse_y) -> None:
    """Show the context window."""
    # noinspection PyUnresolvedReferences, PyProtectedMember
    context_label['text'] = widget._bee2_tooltip_text
    # noinspection PyUnresolvedReferences, PyProtectedMember
    context_label['image'] = widget._bee2_tooltip_img

    window.deiconify()
    window.update_idletasks()
    window.lift()

    # We're going to position tooltips towards the center of the main window.
    # That way they don't tend to stick out, even in multi-window setups.

    # To decide where to put the tooltip, we first want the center of the
    # main window.
    cent_x = TK_ROOT.winfo_rootx() + TK_ROOT.winfo_width() / 2
    cent_y = TK_ROOT.winfo_rooty() + TK_ROOT.winfo_height() / 2

    x_centered = y_centered = True

    # If the widget is smaller than the context window, always center.
    if widget.winfo_width() > window.winfo_width():
        if cent_x > mouse_x + CENT_DIST:
            # Left of center, so place right of the target
            x = widget.winfo_rootx() + widget.winfo_width() + PADDING
            x_centered = False
        elif cent_x < mouse_x - CENT_DIST:
            # Right of center, so place left of the target
            x = widget.winfo_rootx() - window.winfo_width() - PADDING
            x_centered = False

    if widget.winfo_height() > window.winfo_height():
        if cent_y > mouse_y + CENT_DIST:
            # Above center, so place below target
            y = widget.winfo_rooty() + widget.winfo_height() + PADDING
            y_centered = False
        elif cent_y < mouse_y - CENT_DIST:
            # Below center, so place above target
            y = widget.winfo_rooty() - window.winfo_height() - PADDING
            y_centered = False

    if x_centered:  # Center horizontally
        x = (
            widget.winfo_rootx() +
            (widget.winfo_width() - window.winfo_width()) // 2
        )

    if y_centered:
        y = (
            widget.winfo_rooty() +
            (widget.winfo_height() - window.winfo_height()) // 2
        )

        # If both X and Y are centered, the tooltip will appear on top of
        # the mouse and immediately hide. Offset it to fix that.
        if x_centered:
            if mouse_y < cent_y:
                y = widget.winfo_rooty() + widget.winfo_height() + PADDING
            else:
                y = widget.winfo_rooty() - window.winfo_height() - PADDING

    window.geometry('+{}+{}'.format(int(x), int(y)))
开发者ID:BenVlodgi,项目名称:BEE2.4,代码行数:65,代码来源:tooltip.py


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