I am working on a weather app and to add some spice I was thinking on adding a Weather Map, so reached over to https://openweathermap.org/api/weathermaps and got a URL with the image. I researched for many methods on displaying that image on a Tkinter Widget but none of them work. It displays the size of the image but not the image itself. This is my code. Thank you very much.
from tkinter import *
from PIL import ImageTk, Image
import requests
import urllib.request
import base64
root = Tk()
root.title("Weather")
link = "https://tile.openweathermap.org/map/pressure_new/0/0/0.png?appid={APIkey}"
class WebImage:
def __init__(self,url):
u = urllib.request.urlopen(url)
raw_data = u.read()
u.close()
self.image = PhotoImage(data=base64.encodebytes(raw_data))
def get(self):
return self.image
img = WebImage(link_6).get()
imagelab = Label(root, image = img)
imagelab.grid(row = 0, column = 0)
root.mainloop()