如何捕捉 Tk 中的最大化信号? [英] How to catch the maximize signal in Tk?

查看:30
本文介绍了如何捕捉 Tk 中的最大化信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以通过以下方式将命令与窗口的 X 按钮绑定:

You can bind a command with the X button of the window by this:

wm protocol $windowPath WM_DELETE_WINDOW $command

如何对窗口的最大化按钮执行相同操作?

How can I do the same for the maximize button of the window?

推荐答案

它没有标准协议,无论是在 X11 ICCCM 集FreeDesktop 套装.因此,wm 协议 不可能用于它.但是,您可以使用 事件来跟踪窗口的所有大小更改.请注意,如果您将其设置在顶层,您还将收到该窗口内所有小部件的通知,因此您应该在对其采取行动之前检查该事件是否真的与顶层有关,可能如下所示:

There's no standard protocol for it, either among the X11 ICCCM set or the FreeDesktop set. As such, wm protocol cannot possibly be used for it. However, you can use the <Configure> event to track all size changes for a window. Note that if you set it on a toplevel, you will also get notifications for all widgets inside that window, so you should check to see if the event was really about the toplevel before acting on it, perhaps like this:

bind $toplvl <Configure> {
    if {"%W" eq [winfo toplevel "%W"]} {
        ActOnResize %W %w %h [wm attributes %W -zoomed]
    }
}

您可能还想检查 -fullscreen 属性.

You might also want to check the -fullscreen attribute.

这篇关于如何捕捉 Tk 中的最大化信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆