title: Open browser automatically when Python code is executed
body: <p>I am implementing a GUI in Python/Flask.
  The way flask is designed, the local host along with the port number has to be "manually" opened. </p>
  
  <p>Is there a way to automate it so that upon running the code, browser(local host) is automatically opened?</p>
  
  <p>I tried using webbrowser package but it opens the webpage after the session is killed. </p>
  
  <p>I also looked at the following posts but they are going over my head.</p>
  
  <p><a href="https://stackoverflow.com/questions/28056360/shell-script-opening-flask-powered-webpage-opens-two-windows">Shell script opening flask powered webpage opens two windows</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2634235/python-webbrowser-openurl">python webbrowser.open(url)</a></p>
  
  <p>Problem occurs when html pages are rendered based on user inputs.</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>import webbrowser
  
  from flask import Flask
  app = Flask(__name__)
  
  @app.route("/")
  def hello():
      return "Hello World!"
  
  if __name__ == "__main__":
      webbrowser.open_new('http://127.0.0.1:2000/')
      app.run(port=2000)
  </code></pre>