我的Tkinter GUI直接從關聯的last.fm鏈接加載某個歌曲/藝術家組合的專輯封面(如下所示:http://ift.tt/1Jepy2C
,因爲它被ifttt.com提取並重定向到last.fm上的png文件) 當last.fm上沒有專輯封面時,ifttt改爲改爲此圖片:https://ifttt.com/images/no_image_card.png
。在Tkinter找到相同的圖片嗎?
問題是,這個圖像有不同的尺寸比正方形專輯封面,這意味着我做了一個「N/A」PNG文件,如果我收到該圖片,我會插入。不幸的是,只是這樣:
from tkinter import *
local_copy_of_not_available_image = PhotoImage(file="album_not_found.png")
internet_image = PhotoImage(data=b64_Album_data) # fetched b64 data through urllib, which should contain either an album cover or the n/a picture above
if internet_image == local_copy_of_not_available_image:
actual_image = PhotoImage(file="my_album_not_found_square_replacement_picture.png")
else:
actual_image = PhotoImage(data=b64_Album_data)
cover = Label(root, image=actual_image)
cover.pack()
mainloop()
不起作用。顯然,即使它們是相同的圖像,internet_image
中的b64數據與從我的硬盤驅動器加載的文件不同。 我的問題是,如何檢查兩幅圖像在原始數據方面是否完全相同,以便檢測何時將它們的n/a圖片發送給我?
您可以從IFTTT下載N/A圖像,使用Tkinter的方法調整圖像大小,使其非常小並保存到您的PC中。然後在你的代碼中,從IFTTT加載一個圖像,調整它的大小,按字節比較你的PC中的圖像。儘管這有點極端。有沒有其他的方式讓服務器告訴你沒有專輯封面? – TisteAndii
我知道的沒有。但是在這種情況下,專輯封面總是正方形的,而ifttt的n/a圖像是矩形的,我可以比較它們的寬度,如果它們不相等,我會知道我有錯誤圖像。 –
啊,那好多了 – TisteAndii