My tkinter icon isnt show up properly on first launch, it gets downloaded from github and used as the icon, subsequent launches work just fine. The code to download the icon and set it as the tkinter icon is here:
directory = 'C:\\some\\path\\here'
icon_filename = directory + 'icon.ico'
if not os.path.exists(icon_filename):
url = 'https://raw.githubusercontent.com/someuser/somefile.ico'
r = get(url)
f = open(icon_filename, 'wb')
f.write(r.content)
window = tk.Tk()
window.iconbitmap(icon_filename)
window.title("Some Text")
Also i am on windows 11
I have tried to restart the tkinter window after launching it if the icon does not exist, i have tried moving the if not os.path.exists() below window.iconbitmap(), and restarting the whole python script if the file doesnt exist (although i belive those were linux methods)
You'll need to add f.close()
to close the file after you're done writing to it. Or, alternatively, use a context manager to handle closing automatically:
with open(icon_filename, 'wb') as f:
f.write(r.content)