我正在构建一个简单的天气应用程序并为这个项目添加一些“香料”,我计划在 Tkinter 标签上显示天气图。谁能帮我?非常感谢你。这是我的代码的一部分:
from tkinter import *
from PIL import ImageTk, Image
import base64
from io import BytesIO
from urllib.request import urlopen
root = Tk()
root.title("Weather Application - Powered by Python / Tkinter")
def test():
image_url = "https://tile.openweathermap.org/map/pressure_new/0/0/0.png?appid={API_key}&area=worldwide"
response = requests.get(img_url)
image_byt = urlopen(image_url).read()
image_b64 = base64.encodestring(image_byt)
photo = tk.PhotoImage(data = image_b64)
panel = Label(root, image = photo)
panel.pack(side="bottom", fill = "both", expand = "yes")
Button(root, text = "Test", command = test).pack()
root.mainloop()