Advertisement
Najeebsk

PIP-LIST.pyw

Oct 21st, 2024 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.47 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import simpledialog, scrolledtext, messagebox
  3. import subprocess
  4.  
  5. # Function to run pip commands and capture the output
  6. def run_pip_command(command):
  7.     try:
  8.         result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=False)
  9.         return result.stdout + result.stderr
  10.     except Exception as e:
  11.         return str(e)
  12.  
  13. # Function for pip install
  14. def pip_install():
  15.     package = simpledialog.askstring("Install Package", "Enter the package name to install:")
  16.     if package:
  17.         output = run_pip_command(["pip", "install", package])
  18.         output_text.insert(tk.END, output)
  19.  
  20. # Function for pip uninstall
  21. def pip_uninstall():
  22.     package = simpledialog.askstring("Uninstall Package", "Enter the package name to uninstall:")
  23.     if package:
  24.         output = run_pip_command(["pip", "uninstall", "-y", package])
  25.         output_text.insert(tk.END, output)
  26.  
  27. # Function for pip list
  28. def pip_list():
  29.     output = run_pip_command(["pip", "list"])
  30.     output_text.insert(tk.END, output)
  31.  
  32. # Function to search installed packages from pip list
  33. def pip_search():
  34.     search_term = simpledialog.askstring("Search Installed Package", "Enter the package name to search:")
  35.     if search_term:
  36.         # Get the full pip list
  37.         all_packages = run_pip_command(["pip", "list"])
  38.         # Filter the results to show only packages that match the search term
  39.         filtered_packages = [line for line in all_packages.splitlines() if search_term.lower() in line.lower()]
  40.         # Clear the text box and display the filtered results
  41.         output_text.delete(1.0, tk.END)
  42.         if filtered_packages:
  43.             output_text.insert(tk.END, "\n".join(filtered_packages))
  44.         else:
  45.             output_text.insert(tk.END, f"No packages found for search term: {search_term}")
  46.  
  47. # Function to clear the output text box
  48. def clear_output():
  49.     output_text.delete(1.0, tk.END)
  50.  
  51. # Function to save the output to a file
  52. def save_output():
  53.     output = output_text.get(1.0, tk.END).strip()  # Get the current text in the output box
  54.     if output:
  55.         with open("PipList.txt", "w") as file:
  56.             file.write(output)
  57.         messagebox.showinfo("Save Output", "Output successfully saved to PipList.txt")
  58.     else:
  59.         messagebox.showwarning("Save Output", "No output to save!")
  60.  
  61. # Set up the main window
  62. root = tk.Tk()
  63. root.title("Najeeb Pip Manager")
  64.  
  65. # Create buttons for each pip action
  66. btn_install = tk.Button(root, text="Pip Install", command=pip_install)
  67. btn_install.grid(row=0, column=0, padx=10, pady=10)
  68.  
  69. btn_uninstall = tk.Button(root, text="Pip Uninstall", command=pip_uninstall)
  70. btn_uninstall.grid(row=0, column=1, padx=10, pady=10)
  71.  
  72. btn_list = tk.Button(root, text="Pip List", command=pip_list)
  73. btn_list.grid(row=0, column=2, padx=10, pady=10)
  74.  
  75. btn_search = tk.Button(root, text="Pip Search (Installed)", command=pip_search)
  76. btn_search.grid(row=0, column=3, padx=10, pady=10)
  77.  
  78. btn_clear = tk.Button(root, text="Clear Output", command=clear_output)
  79. btn_clear.grid(row=0, column=4, padx=10, pady=10)
  80.  
  81. # Create a "Save Output" button
  82. btn_save = tk.Button(root, text="Save Output", command=save_output)
  83. btn_save.grid(row=0, column=5, padx=10, pady=10)
  84.  
  85. # Create a scrolled text box to show output
  86. output_text = scrolledtext.ScrolledText(root, height=20, width=80)
  87. output_text.grid(row=1, column=0, columnspan=6, padx=10, pady=10)
  88.  
  89. # Start the Tkinter event loop
  90. root.mainloop()
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement