import requests
import tkinter as tk
from tkinter import *
window = tk.Tk()
window.title("Image Downloader")
window.geometry("800x400")
def download():
url_entry.get()
url = ("https://" str(url_entry))
r = requests.get(url)
with open("downloaded_image.png", "wb") as f:
f.write(r.content)
url_label = Label(window, text="Enter URL Here:", fg="black", font="Helvetica 14 bold")
url_label.place(x=0, y=0)
url_entry = Entry(window)
url_entry.place(x=155, y=5)
how_to_get_url_label = Label(window, text="Find the image you want to download > right click > copy image address",
font="Helvetica 14 bold")
how_to_get_url_label.place(x=0 , y=27)
download_button = Button(window, text="Download", font="Helvetica 9 bold", fg="black", bg="green", pady=-5, padx=-5,
command=download)
download_button.place(x=285, y=2.5)
window.mainloop()
給出錯誤訊息“URL 的標簽無效”,我不太清楚為什么。我正在嘗試使用 tkinter 和 requests 一起制作影像下載器。
uj5u.com熱心網友回復:
您需要修復下載函式的定義并分配 Entry.get() 方法回傳的值,即:
def download():
url_text = url_entry.get()
url = ("https://" str(url_text))
r = requests.get(url)
with open("downloaded_image.png", "wb") as f:
f.write(r.content)
除此之外,它應該可以正常作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/417963.html
標籤:
上一篇:在電子郵件正文中粘貼影像
下一篇:按下按鈕將影像添加到幀
