pythonchromium-embeddedcefpython

CEF Python Hide Browser


I create a Browser:

browser = cef.CreateBrowserSync(url=os.path.dirname(os.path.abspath(__file__))+'\\gui.html', window_title="Title")

Is there any way to hide and show the window whenever I want?


Solution

  • If you use the "wxpython.py" example then you can call MainFrame.Hide() to hide window and Show() to show it.

    If using the "hello_world.py" example then you would need to make a native OS call using for example ctypes. For Windows the code would be:

    import ctypes
    SW_SHOW = 5
    SW_HIDE = 0
    hwnd = browser.GetWindowHandle()
    ctypes.windll.user32.ShowWindow(hwnd, SW_HIDE)
    ctypes.windll.user32.ShowWindow(hwnd, SW_SHOW)