关闭 Imgui 窗口:这看起来应该很容易。一个人如何做到这一点?

don*_*lan 0 python-3.x imgui pyimgui

我已经开始使用该imgui系统来可视化“任何”。我在最初的几个小时里,遇到了一些看似常见的障碍。

然而,尽管我可以看到对 ImGui 的 C++ 版本(我最终将过渡到该版本)有一些相当好的支持,但 python imgui 内容大多是模糊的。

我正在寻找的是以下问题的解决方案:

while not glfw.window_should_close(window):
  ...
  imgui.new_frame()
  imgui.begin("foo-window", closable=True)
  imgui.end()
Run Code Online (Sandbox Code Playgroud)

一切正常。然而,窗户并没有关闭。我知道窗口不会关闭,因为它总是在每个循环中创建。

我正在寻找的是:

如何检测和识别特定窗口已关闭,并阻止其重新生成?

小智 6

我对 Python 的 imGui 一点也不熟悉,但如果它完全遵循与 c++ 的 imGui 类似的模式,那么您需要遵循以下模式:

static bool show_welcome_popup = true;

if(show_welcome_popup)
{
    showWelcomePopup(&show_welcome_popup);
}

void showWelcomePopup(bool* p_open)
{
    //The window gets created here. Passing the bool to ImGui::Begin causes the "x" button to show in the top right of the window. Pressing the "x" button toggles the bool passed to it as "true" or "false"
    //If the window cannot get created, it will call ImGui::End
    if(!ImGui::Begin("Welcome", p_open))
    {
        ImGui::End();
    } 
    else
    {
        ImGui::Text("Welcome");   
        ImGui::End();
    }
}
Run Code Online (Sandbox Code Playgroud)