Retrieving An Icon File From A GitHub Repository In Python

122 views Asked by At

I want to know how I could retrieve an ICO (icon) file from a GitHub repository. And then after that, put it as the iconbitmap for a Tkinter window.

Here's my code:

import tkinter as tk

window = tk.Tk()
window.title("Feedback And Rating")
window.geometry("300x350")
window.iconbitmap("https://raw.githubusercontent.com/AngusAU293/Application-Assets/main/Feedback%20And%20Rating%20Example/icon.ico")

I'm using Python 3.

1

There are 1 answers

0
ZCGCoder On

You can download the file using urllib.request, then set the icon to the downloaded file. Or, as Karl suggested, download the icon beforehand and place in the SAME directory as the Python file, so that the application doesn't need internet to run.

import urllib.request
import tkinter as tk

window = tk.Tk()
window.title("Feedback And Rating")
window.geometry("300x350")
urllib.request.urlretrieve("https://raw.githubusercontent.com/AngusAU293/Application-Assets/main/Feedback%20And%20Rating%20Example/icon.ico", "icon.ico")
window.iconbitmap("icon.ico")