0

I'm on windows using vscode,

while True:
    command = input("enter to next, 0 to append and next (or type 'e' to quit): ")
    
    if command.lower() == 'e':
        print("Exiting the program.")
        break

    if n >= len(name):
        print("No more destinations left.")
        break
    if command == '0':
        newlist.append(name[n] + "\n")
        print(f"Appended: {name[n]}")

    destination = name[n]
    n += 1

    # Build Google Maps directions link safely
    url = "https://www.google.com/maps/dir/" + urllib.parse.quote(origin) + "/" + urllib.parse.quote(destination)

    # Open in browser
    #webbrowser.open(url, new=2)   # 2 = open in new tab if possible
    webbrowser.open_new_tab(url)

Opening google maps through python code, working but focus of my curser is not staying in terminal, i have to manually bring focus back to terminal for next command.

2
  • it is rather not problem with Python but with system (Windows) which automatically switch focus to browser. Maybe with pyautogui or pywinauto you could switch focus to other window - ie. to terminal. Commented Aug 27 at 13:11
  • 1
    Disable auto raise: webbrowser.open_new_tab(url, autoraise=False) Commented Aug 27 at 13:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.