<small id='3KFOP'></small><noframes id='3KFOP'>

<i id='3KFOP'><tr id='3KFOP'><dt id='3KFOP'><q id='3KFOP'><span id='3KFOP'><b id='3KFOP'><form id='3KFOP'><ins id='3KFOP'></ins><ul id='3KFOP'></ul><sub id='3KFOP'></sub></form><legend id='3KFOP'></legend><bdo id='3KFOP'><pre id='3KFOP'><center id='3KFOP'></center></pre></bdo></b><th id='3KFOP'></th></span></q></dt></tr></i><div id='3KFOP'><tfoot id='3KFOP'></tfoot><dl id='3KFOP'><fieldset id='3KFOP'></fieldset></dl></div>
<legend id='3KFOP'><style id='3KFOP'><dir id='3KFOP'><q id='3KFOP'></q></dir></style></legend>
      • <bdo id='3KFOP'></bdo><ul id='3KFOP'></ul>

    1. <tfoot id='3KFOP'></tfoot>
    2. “wait_window"是什么意思?方法呢?

      时间:2023-10-09
      • <small id='lvX2E'></small><noframes id='lvX2E'>

        <i id='lvX2E'><tr id='lvX2E'><dt id='lvX2E'><q id='lvX2E'><span id='lvX2E'><b id='lvX2E'><form id='lvX2E'><ins id='lvX2E'></ins><ul id='lvX2E'></ul><sub id='lvX2E'></sub></form><legend id='lvX2E'></legend><bdo id='lvX2E'><pre id='lvX2E'><center id='lvX2E'></center></pre></bdo></b><th id='lvX2E'></th></span></q></dt></tr></i><div id='lvX2E'><tfoot id='lvX2E'></tfoot><dl id='lvX2E'><fieldset id='lvX2E'></fieldset></dl></div>
                <bdo id='lvX2E'></bdo><ul id='lvX2E'></ul>

                <legend id='lvX2E'><style id='lvX2E'><dir id='lvX2E'><q id='lvX2E'></q></dir></style></legend>

                  <tbody id='lvX2E'></tbody>
                <tfoot id='lvX2E'></tfoot>

                本文介绍了“wait_window"是什么意思?方法呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                似乎调用这个方法的对象等待作为参数传递的窗口被销毁,然后继续它自己的循环...

                Misc类的文档字符串中,我们可以观察到:

                <块引用>

                def wait_window(self, window=None):"""等到一个WIDGET被销毁.如果没有给出参数,则使用 self."""

                乍一看,这个方法似乎可以制作一个 Toplevel 模态,但事实并非如此.要制作 Toplevel 模态,我们必须使用 grab_set() 方法.

                我看到了其他解释:

                <块引用>

                wait_window 似乎在给定的小部件作为参数传递之前不会返回不会被破坏.

                从另一个地方:

                <块引用>

                wait_window(widget) - 创建一个等待给定的本地事件要销毁的小部件.此循环不会影响应用程序的主循环.

                根据 effbot 文档,我们有:

                <块引用>

                wait_window 进入本地事件循环,直到给定的窗口被销毁(通过 destroy 方法,或显式地通过窗口管理器):

                widget.wait_window(window)

                window 等待 window(本身)究竟意味着什么?

                似乎在调用 wait_window 之后的代码不会执行,直到传递给同一方法的窗口没有被破坏.在下面的工作示例中,我们可以看到刚才所说的证明:

                从 tkinter 导入 *def on_win_request(父):对话框 = 顶层()parent.wait_window(对话框)# 只有在对话框"被销毁时才执行print("小事件循环完成!")r = Tk()b = Button(r, text='New Window', command=lambda: on_win_request(r))b.pack()b2 = Button(r, text='Hello!', command=lambda: print("hello"))b2.pack()r.mainloop()

                "Mini-event loop finished!" 只会在名为 dialog 的本地 Toplevel 小部件被销毁时打印.

                那么,究竟应该在什么实际情况下使用这种方法呢?

                解决方案

                就像文档中所说的,它一直等到给定的窗口被销毁.它主要用于模式弹出窗口,尽管它本身并不构成窗口模式.在目标窗口被销毁之前,对该函数的调用不会返回.要创建模态窗口,您还必须进行抓取.

                最常见的用途是创建一个 Toplevel 的实例,用小部件填充该窗口,然后等待窗口关闭,然后再执行其他操作.在等待期间,tkinter 能够继续正常处理事件.

                例如,您可以禁用(或推迟创建)主 GUI,弹出服务条款"通知,并等待用户确认服务条款、版权、许可等.一旦窗口被销毁后,您可以完成初始化,或启用一些小部件等.

                标准文件对话框就是一个很好的例子:你弹出对话框,然后你的代码等待用户选择一个文件,然后它使用返回的文件名.在内部,对话框的实现使用 wait_window 以便在对话框关闭之前它不会返回.

                It seems that the object that calls this method waits for the window passed as parameter to be destroyed before continue with its own loop...

                From the doc strings of the Misc class, we can observe:

                def wait_window(self, window=None):
                    """Wait until a WIDGET is destroyed.
                    If no parameter is given self is used."""
                

                At first glance, it seems like this method can make a Toplevel modal, but this is not true. To make a Toplevel modal, we have to use the grab_set() method.

                I have see around other explanations:

                wait_window seems to not return until the given widget passed as parameter is not destroyed.

                From another place:

                wait_window(widget) - Creates a local event that waits for the given widget to be destroyed. This loop doesn't affect the application's mainloop.

                From the effbot documentation, we have:

                The wait_window enters a local event loop, and doesn’t return until the given window is destroyed (either via the destroy method, or explicitly via the window manager):

                widget.wait_window(window)
                

                What exactly means for a window to wait for window (itself)?

                It seems that the code that comes after the call to wait_window is not executed until the window passed to the same method is not destroyed. In the following working example, we can see a proof on what just said:

                from tkinter import *
                
                def on_win_request(parent):
                    dialog = Toplevel()
                    parent.wait_window(dialog)
                    # executed only when "dialog" is destroyed
                    print("Mini-event loop finished!")
                
                r = Tk()
                b = Button(r, text='New Window', command=lambda: on_win_request(r))
                b.pack()
                b2 = Button(r, text='Hello!', command=lambda: print("hello"))
                b2.pack()
                r.mainloop()
                

                "Mini-event loop finished!" will be printed only when the local Toplevel widget called dialog is destroyed.

                So, in exactly what real circumstances should I use this method?

                解决方案

                Like the documentation states, it waits until the given window is destroyed. It is mostly used for modal popups, though it doesn't itself make a window modal. The call to the function simply doesn't return until the target window is destroyed To make a modal window you have to do a grab as well.

                The most common use is to create an instance of Toplevel, populate that window with widgets, then wait for the window to be dismissed before doing some other action. While it is waiting, tkinter is able to continue to process events as normal.

                For instance, you can disable (or defer creation of) the main GUI, pop up a "terms of service" notice, and wait for the user to acknowledge the terms of service, copyright, license, etc. Once the window is destroyed you can then finish initialization, or enable some widgets, etc.

                The standard file dialog is a perfect example: you pop up the dialog, then your code waits for the user to pick a file, then it uses the filename that was returned. Internally, the implementation of the dialog uses wait_window so that it doesn't return until the dialog is dismissed.

                这篇关于“wait_window"是什么意思?方法呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:在 Python 中弹出图形对话框的最简单的跨平台方法 下一篇:在 Python (PyQt4) 中显示弹出窗口

                相关文章

                最新文章

                • <bdo id='5FUxA'></bdo><ul id='5FUxA'></ul>
                <tfoot id='5FUxA'></tfoot>

                <small id='5FUxA'></small><noframes id='5FUxA'>

                    <legend id='5FUxA'><style id='5FUxA'><dir id='5FUxA'><q id='5FUxA'></q></dir></style></legend>
                    <i id='5FUxA'><tr id='5FUxA'><dt id='5FUxA'><q id='5FUxA'><span id='5FUxA'><b id='5FUxA'><form id='5FUxA'><ins id='5FUxA'></ins><ul id='5FUxA'></ul><sub id='5FUxA'></sub></form><legend id='5FUxA'></legend><bdo id='5FUxA'><pre id='5FUxA'><center id='5FUxA'></center></pre></bdo></b><th id='5FUxA'></th></span></q></dt></tr></i><div id='5FUxA'><tfoot id='5FUxA'></tfoot><dl id='5FUxA'><fieldset id='5FUxA'></fieldset></dl></div>