当在TkInter中激活模式对话框时,如何禁用窗口控件? [英] How to disable window controls when a modal dialog box is active in TkInter?

查看:674
本文介绍了当在TkInter中激活模式对话框时,如何禁用窗口控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用TkInter编写Python应用程序.在某个时候,应用程序(root)显示一个对话框(dlg,它是Toplevel).为了使对话框成为模态,我使用以下代码:

I am writing a Python application with TkInter. At some point the application (root) displays a dialog box (dlg, which is a Toplevel). In order to make the dialog modal I use the following code:

dlg.focus_set()
dlg.grab_set()
dlg.transient(root)
root.wait_window(dlg)

这确实取消了对话框外的自定义"事件(例如主应用程序窗口中的小部件),但是并没有取消窗口管理器事件,因此例如在主应用程序窗口上单击可以使其重新获得焦点并它可以移动,调整大小-甚至可以关闭! -当模式"对话框仍处于打开状态时.

This indeed cancels "custom" events outside the dialog box (like the widgets in the main application window), but it does NOT cancel the window manager events, so that for example clicking on the main application window has it regain focus and it can be moved, resized - and even closed! - while the "modal" dialog is still open.

如何使对话框真正成为模态对话框,以便在对话框处于活动状态时也暂停主应用程序窗口的窗口管理器事件?

How can I make my dialog truly modal, so that window manager events for the main application window are also suspended while the dialog box is active?

我正在Ubuntu 15.04上使用Python 3.4.3.

I am using Python 3.4.3 on Ubuntu 15.04.

推荐答案

尝试这种方式:

dlg.focus_set()
dlg.grab_set()
dlg.transient(root)
dlg.wait_window(dlg)

这篇关于当在TkInter中激活模式对话框时,如何禁用窗口控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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