# Multiple Servers

Create multiple windows, some of which have their own servers, both before and after webview.start() is called.

import bottle

import webview

# We'll have a global list of our windows so our web app can give us information
# about them
windows = []

# A simple function to format a description of our servers
def serverDescription(server):
    return f"{str(server).replace('<','').replace('>','')}"

# Define a couple of simple web apps using Bottle
app1 = bottle.Bottle()

def hello():
    return '<h1>Second Window</h1><p>This one is a web app and has its own server.</p>'

app2 = bottle.Bottle()

def hello():
    head = """  <head>
                    <style type="text/css">
                        table {
                          font-family: arial, sans-serif;
                          border-collapse: collapse;
                          width: 100%;

                        td, th {
                          border: 1px solid #dddddd;
                          text-align: center;
                          padding: 8px;

                        tr:nth-child(even) {
                          background-color: #dddddd;
    body = f""" <body>
                    <h1>Third Window</h1>
                    <p>This one is another web app and has its own server. It was started after webview.start.</p>
                    <p>Server Descriptions: </p>
                            <th>IP Address</th>
                            <td>Global Server</td>
                            <td>{webview.http.global_server.address if not webview.http.global_server is None else 'None'}</td>
                            <td>First Window</td>
                            <td>{windows[0]._server.address if not windows[0]._server is None else 'None'}</td>
                            <td>Second Window</td>
                            <td>Third Window</td>
    return head + body

def third_window():
    # Create a new window after the loop started
    windows.append(webview.create_window('Window #3', url=app2))

if __name__ == '__main__':
    # Master window
            'Window #1',
            html='<h1>First window</h1><p>This one is static HTML and just uses the global server for api calls.</p>',
    windows.append(webview.create_window('Window #2', url=app1, http_port=3333))
    webview.start(third_window, http_server=True, http_port=3334)