在 Python TKinter 中创建弹出窗口时禁用底层窗口 [英] Disable the underlying window when a popup is created in Python TKinter
本文介绍了在 Python TKinter 中创建弹出窗口时禁用底层窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个主框架(称为a
)和一个弹出式顶层(称为b
).当 b
处于活动状态"时,如何确保用户无法点击 a
中的任何内容?
I have a master Frame (call it a
), and a popup Toplevel (call it b
). How do I make sure the user cannot click on anything in a
while b
is "alive"?
推荐答案
如果您不想隐藏根目录而只是确保用户只能与弹出窗口交互,则可以使用 grab_set()
和 grab_release()
.
If you don't want to hide the root but just make sure the user can only interact with the popup, you can use grab_set()
and grab_release()
.
b.grab_set() # when you show the popup
# do stuff ...
b.grab_release() # to return to normal
或者,您可以withdraw()
根使其不可见:
Alternatively, you could withdraw()
the root to make it invisible:
a.withdraw()
将使根保持活动状态,但只有 b
可见.
will leave the root alive, but only b
visible.
如果你需要它回来,你可以做
If you need it back, you can do
a.deiconify()
这篇关于在 Python TKinter 中创建弹出窗口时禁用底层窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文