def read_menu_event(window, choices, timeout=None):
    """Reads the window event.  Return `None` if no event to respond to, otherwise
    return the selected menu item's text."""
    event, values = window.read(timeout=timeout)

    if not event:
        return "toggle gui"

    # Update the values to clear the current selection, since we've read it.
    window["cmd list"].update(values=choices)

    if event == "Cancel":
        return "toggle gui"

    if not values or not values["cmd list"]:
        return None # Got no command, do nothing.

    return values["cmd list"][0]