本文整理汇总了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)))