Results 1 to 3 of 3

Thread: Python - How to close browser windows opened by webbrowser.open()

  1. #1
    Join Date
    Oct 2012
    Beans
    13

    Python - How to close browser windows opened by webbrowser.open()

    I'm trying to open a webpage from a python script then close it after a set amount of time (or when the user presses a key).

    However I'm not sure what would be the best way to close the browser window that webrowser.open() creates?

  2. #2
    wojox is offline I Ubuntu, Therefore, I Am
    Join Date
    Apr 2009
    Beans
    8,628

    Re: Python - How to close browser windows opened by webbrowser.open()

    You could add
    Code:
    webrowser.close()
    to the end of your func.

    When you close the script the object should be destroyed automatically.

  3. #3
    Join Date
    Oct 2012
    Beans
    13

    Re: Python - How to close browser windows opened by webbrowser.open()

    Quote Originally Posted by wojox View Post
    You could add
    Code:
    webrowser.close()
    to the end of your func.

    When you close the script the object should be destroyed automatically.
    Ok I tried this but it doesn't seem to work.

    Code:
    import webbrowser
    
    webbrowser.open("http://www.google.co.uk")
    webbrowser.close()
    It comes up like this when I run it from terminal:

    Code:
    user@pc:~/Programming$ python test.py
    Traceback (most recent call last):
      File "test.py", line 4, in <module>
        webbrowser.close()
    AttributeError: 'module' object has no attribute 'close'
    user@pc:~/Programming$ QDBusConnection: session D-Bus connection created before QCoreApplication. Application may misbehave.
    QDBusConnection: session D-Bus connection created before QCoreApplication. Application may misbehave.
    I also had to press the return key before it would finish executing the program.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •