Reason
I previously asked the same question but using a different language (small basic), yet received little help. For this reason, I re-scripted the program in python hoping to reach a wider audience, despite the fact I am a beginner with python.
What am I trying to do?
I'm trying to create a program that generates a random URL subdirectory for an open image database and then opens the URL in the default browser.
What's wrong?
Despite the fact I instruct the code to open over the current tab using
new=0, autoraise=True
No matter what I do it opens a new instance of the page, which is pointless as the base URL remains the same and only the directories change.
My code
import webbrowser
from tkinter import *
import random
import string
root = Tk()
root.title("Image Browser")
root.geometry("300x70")
def google():
rannums = ''.join(random.choice(string.digits) for n in range(4))
ranstring = ''.join(random.choice(string.ascii_lowercase) for i in range(2))
urlsuffix = ranstring + rannums
url = "https://prnt.sc/" + urlsuffix
webbrowser.open(url, new=0, autoraise=True)
root.focus_force()
mygoogle = Button(root, text="Random Image", command=google).pack(pady=20)
root.mainloop()