# Buggy code
def create_window(
    uid,
    title,
    url,
    width,
    height,
    resizable,
    fullscreen,
    min_size,
    confirm_quit,
    background_color,
    debug,
    js_api,
    text_select,
    webview_ready,
):
    def create():
        window = BrowserView.BrowserForm(
            uid,
            title,
            url,
            width,
            height,
            resizable,
            fullscreen,
            min_size,
            confirm_quit,
            background_color,
            debug,
            js_api,
            text_select,
            webview_ready,
        )
        BrowserView.instances[uid] = window
        window.Show()

        if uid == "master":
            app.Run()

    webview_ready.clear()
    app = WinForms.Application

    if uid == "master":
        set_ie_mode()
        if sys.getwindowsversion().major >= 6:
            windll.user32.SetProcessDPIAware()

        app.EnableVisualStyles()
        app.SetCompatibleTextRenderingDefault(False)

        thread = Thread(ThreadStart(create))
        thread.SetApartmentState(ApartmentState.STA)
        thread.Start()
        thread.Join()
    else:
        BrowserView.instances["master"].Invoke(Func[Type](create))


# Traceback (KeyError)
Exception in thread Thread-3:
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Program Files\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "ui_pywebview.py", line 23, in create_second_window
second_window = webview.create_window("Window 2", os.path.abspath("web\\window2.html"), js_api=SecondWindowApi)
File "C:\Program Files\Python36\lib\site-packages\webview\__init__.py", line 183, in create_window
background_color, debug, js_api, text_select, _webview_ready)
File "C:\Program Files\Python36\lib\site-packages\webview\winforms.py", line 252, in create_window
BrowserView.instances['master'].Invoke(Func[Type](create))
KeyError: 'master'

# Fixed code
def create_window(
    uid,
    title,
    url,
    width,
    height,
    resizable,
    fullscreen,
    min_size,
    confirm_quit,
    background_color,
    debug,
    js_api,
    text_select,
    webview_ready,
):
    def create():
        window = BrowserView.BrowserForm(
            uid,
            title,
            url,
            width,
            height,
            resizable,
            fullscreen,
            min_size,
            confirm_quit,
            background_color,
            debug,
            js_api,
            text_select,
            webview_ready,
        )
        BrowserView.instances[uid] = window
        window.Show()

        if uid == "master":
            app.Run()

    webview_ready.clear()
    app = WinForms.Application

    if uid == "master":
        set_ie_mode()
        if sys.getwindowsversion().major >= 6:
            windll.user32.SetProcessDPIAware()

        app.EnableVisualStyles()
        app.SetCompatibleTextRenderingDefault(False)

        thread = Thread(ThreadStart(create))
        thread.SetApartmentState(ApartmentState.STA)
        thread.Start()
        thread.Join()
    else:
        i = list(BrowserView.instances.values())[0]  # arbitrary instance
        i.Invoke(Func[Type](create))