URL 的标签无效。不太确定为什么
URL has an invalid label. Not too sure as of why
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 一起制作图像下载器。
您需要修复下载函数的定义并分配 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)
除此之外它应该工作得很好。
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 一起制作图像下载器。
您需要修复下载函数的定义并分配 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)
除此之外它应该工作得很好。