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()
Gives error message "URL has an invalid label" and I'm not too sure why. I'm attempting to make an image downloader using tkinter and requests together.
CodePudding user response:
You need to fix your definition of download function and assign value returned by Entry.get() method, i.e.:
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)
Besides that it should work just fine.
