Advertisement
Najeebsk

SEARCH-PICTURES.py

Mar 15th, 2024
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.47 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import messagebox
  3. import subprocess
  4.  
  5. def download_image():
  6.     keyword = keyword_entry.get()
  7.     savedir = savedir_entry.get()
  8.     target = target_var.get()
  9.     limits = limits_scale.get()
  10.     nthreadings = nthreadings_scale.get()
  11.  
  12.     # Constructing the command to execute
  13.     command = ["imagedl"]
  14.     if keyword:
  15.         command.extend(["-k", keyword])
  16.     if savedir:
  17.         command.extend(["-s", savedir])
  18.     if target:
  19.         command.extend(["-t", target])
  20.     if limits:
  21.         command.extend(["-l", str(limits)])
  22.     if nthreadings:
  23.         command.extend(["-n", str(nthreadings)])
  24.  
  25.     # Executing the command
  26.     try:
  27.         subprocess.run(command, check=True)
  28.         messagebox.showinfo("Download Successful", "Images downloaded successfully!")
  29.     except subprocess.CalledProcessError:
  30.         messagebox.showerror("Download Error", "An error occurred while downloading images.")
  31.  
  32. # Create the main window
  33. root = tk.Tk()
  34. root.title("Image Downloader")
  35.  
  36. # Create input fields and labels
  37. keyword_label = tk.Label(root, text="Keyword:")
  38. keyword_label.grid(row=0, column=0, padx=10, pady=5)
  39. keyword_entry = tk.Entry(root, width=50)
  40. keyword_entry.grid(row=0, column=1, padx=10, pady=5)
  41.  
  42. savedir_label = tk.Label(root, text="Save Directory:")
  43. savedir_label.grid(row=1, column=0, padx=10, pady=5)
  44. savedir_entry = tk.Entry(root, width=50)
  45. savedir_entry.grid(row=1, column=1, padx=10, pady=5)
  46.  
  47. target_label = tk.Label(root, text="Target:")
  48. target_label.grid(row=2, column=0, padx=10, pady=5)
  49. targets = ["google", "baidu", "bing"]
  50. target_var = tk.StringVar(root)
  51. target_var.set(targets[0])  # Default value
  52. target_dropdown = tk.OptionMenu(root, target_var, *targets)
  53. target_dropdown.grid(row=2, column=1, padx=10, pady=5)
  54.  
  55. limits_label = tk.Label(root, text="Limits:")
  56. limits_label.grid(row=3, column=0, padx=10, pady=5)
  57. limits_scale = tk.Scale(root, from_=10, to=1000, orient="horizontal")
  58. limits_scale.grid(row=3, column=1, padx=10, pady=5)
  59.  
  60. nthreadings_label = tk.Label(root, text="Number of Threadings:")
  61. nthreadings_label.grid(row=4, column=0, padx=10, pady=5)
  62. nthreadings_scale = tk.Scale(root, from_=0, to=30, orient="horizontal", tickinterval=5, showvalue=True)
  63. nthreadings_scale.grid(row=4, column=1, padx=10, pady=5)
  64.  
  65. # Create download button
  66. download_button = tk.Button(root, text="Download", command=download_image)
  67. download_button.grid(row=5, columnspan=2, padx=10, pady=5)
  68.  
  69. # Run the GUI
  70. root.mainloop()
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement