Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import simpledialog, scrolledtext, messagebox
- import subprocess
- # Function to run pip commands and capture the output
- def run_pip_command(command):
- try:
- result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=False)
- return result.stdout + result.stderr
- except Exception as e:
- return str(e)
- # Function for pip install
- def pip_install():
- package = simpledialog.askstring("Install Package", "Enter the package name to install:")
- if package:
- output = run_pip_command(["pip", "install", package])
- output_text.insert(tk.END, output)
- # Function for pip uninstall
- def pip_uninstall():
- package = simpledialog.askstring("Uninstall Package", "Enter the package name to uninstall:")
- if package:
- output = run_pip_command(["pip", "uninstall", "-y", package])
- output_text.insert(tk.END, output)
- # Function for pip list
- def pip_list():
- output = run_pip_command(["pip", "list"])
- output_text.insert(tk.END, output)
- # Function to search installed packages from pip list
- def pip_search():
- search_term = simpledialog.askstring("Search Installed Package", "Enter the package name to search:")
- if search_term:
- # Get the full pip list
- all_packages = run_pip_command(["pip", "list"])
- # Filter the results to show only packages that match the search term
- filtered_packages = [line for line in all_packages.splitlines() if search_term.lower() in line.lower()]
- # Clear the text box and display the filtered results
- output_text.delete(1.0, tk.END)
- if filtered_packages:
- output_text.insert(tk.END, "\n".join(filtered_packages))
- else:
- output_text.insert(tk.END, f"No packages found for search term: {search_term}")
- # Function to clear the output text box
- def clear_output():
- output_text.delete(1.0, tk.END)
- # Function to save the output to a file
- def save_output():
- output = output_text.get(1.0, tk.END).strip() # Get the current text in the output box
- if output:
- with open("PipList.txt", "w") as file:
- file.write(output)
- messagebox.showinfo("Save Output", "Output successfully saved to PipList.txt")
- else:
- messagebox.showwarning("Save Output", "No output to save!")
- # Set up the main window
- root = tk.Tk()
- root.title("Najeeb Pip Manager")
- # Create buttons for each pip action
- btn_install = tk.Button(root, text="Pip Install", command=pip_install)
- btn_install.grid(row=0, column=0, padx=10, pady=10)
- btn_uninstall = tk.Button(root, text="Pip Uninstall", command=pip_uninstall)
- btn_uninstall.grid(row=0, column=1, padx=10, pady=10)
- btn_list = tk.Button(root, text="Pip List", command=pip_list)
- btn_list.grid(row=0, column=2, padx=10, pady=10)
- btn_search = tk.Button(root, text="Pip Search (Installed)", command=pip_search)
- btn_search.grid(row=0, column=3, padx=10, pady=10)
- btn_clear = tk.Button(root, text="Clear Output", command=clear_output)
- btn_clear.grid(row=0, column=4, padx=10, pady=10)
- # Create a "Save Output" button
- btn_save = tk.Button(root, text="Save Output", command=save_output)
- btn_save.grid(row=0, column=5, padx=10, pady=10)
- # Create a scrolled text box to show output
- output_text = scrolledtext.ScrolledText(root, height=20, width=80)
- output_text.grid(row=1, column=0, columnspan=6, padx=10, pady=10)
- # Start the Tkinter event loop
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement