NoahVerner
NoahVerner

Reputation: 867

How can I make this function open a new tab in my actual browser on Python?

I just started learning software development with GUI elements and so far I have managed to come up with this program, that the only thing it does is to create a GUI element that has a button which opens a new chrome window when clicked:

import tkinter as tk #
import subprocess
import os
import sys

root = tk.Tk()
root.geometry('500x400')
root.title("Bulk upload to OpenSea")

main_directory = os.path.join(sys.path[0])
def open_chrome_profile():
    subprocess.Popen(
        [
            "start",
            "chrome",
            "--remote-debugging-port=8989",
            "--user-data-dir=" + main_directory + "/chrome_profile",
        ],
        shell=True,
    )

#####BUTTON ZONE#######
open_browser = tk.Button(root, width=20,  text="Open Chrome Browser", command=open_chrome_profile)
open_browser.grid(row=22, column=1)
root.mainloop()

GUI preview:

preview1

Result after clicking the "Open Chrome Browser" button: preview2

However, I noticed that the chrome browser deployed is not the real one I use, I know that it uses the statement "--user-data-dir=" + main_directory + "/chrome_profile" to deploy a driver-like version of my browser, but I don't know how could I get the corresponding path (and its profile) to my actual chrome browser.

How should the function open_chrome_profile() be changed in order to open a new tab in my actual chrome browser?

Upvotes: 2

Views: 507

Answers (1)

acw1668
acw1668

Reputation: 46687

You can simply use webbrowser module:

webbrowser.open_new_tab('https://google.com')

Upvotes: 1

Related Questions