Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import messagebox
- import subprocess
- def download_image():
- keyword = keyword_entry.get()
- savedir = savedir_entry.get()
- target = target_var.get()
- limits = limits_scale.get()
- nthreadings = nthreadings_scale.get()
- # Constructing the command to execute
- command = ["imagedl"]
- if keyword:
- command.extend(["-k", keyword])
- if savedir:
- command.extend(["-s", savedir])
- if target:
- command.extend(["-t", target])
- if limits:
- command.extend(["-l", str(limits)])
- if nthreadings:
- command.extend(["-n", str(nthreadings)])
- # Executing the command
- try:
- subprocess.run(command, check=True)
- messagebox.showinfo("Download Successful", "Images downloaded successfully!")
- except subprocess.CalledProcessError:
- messagebox.showerror("Download Error", "An error occurred while downloading images.")
- # Create the main window
- root = tk.Tk()
- root.title("Image Downloader")
- # Create input fields and labels
- keyword_label = tk.Label(root, text="Keyword:")
- keyword_label.grid(row=0, column=0, padx=10, pady=5)
- keyword_entry = tk.Entry(root, width=50)
- keyword_entry.grid(row=0, column=1, padx=10, pady=5)
- savedir_label = tk.Label(root, text="Save Directory:")
- savedir_label.grid(row=1, column=0, padx=10, pady=5)
- savedir_entry = tk.Entry(root, width=50)
- savedir_entry.grid(row=1, column=1, padx=10, pady=5)
- target_label = tk.Label(root, text="Target:")
- target_label.grid(row=2, column=0, padx=10, pady=5)
- targets = ["google", "baidu", "bing"]
- target_var = tk.StringVar(root)
- target_var.set(targets[0]) # Default value
- target_dropdown = tk.OptionMenu(root, target_var, *targets)
- target_dropdown.grid(row=2, column=1, padx=10, pady=5)
- limits_label = tk.Label(root, text="Limits:")
- limits_label.grid(row=3, column=0, padx=10, pady=5)
- limits_scale = tk.Scale(root, from_=10, to=1000, orient="horizontal")
- limits_scale.grid(row=3, column=1, padx=10, pady=5)
- nthreadings_label = tk.Label(root, text="Number of Threadings:")
- nthreadings_label.grid(row=4, column=0, padx=10, pady=5)
- nthreadings_scale = tk.Scale(root, from_=0, to=30, orient="horizontal", tickinterval=5, showvalue=True)
- nthreadings_scale.grid(row=4, column=1, padx=10, pady=5)
- # Create download button
- download_button = tk.Button(root, text="Download", command=download_image)
- download_button.grid(row=5, columnspan=2, padx=10, pady=5)
- # Run the GUI
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement