make me gui app in python that can choose an app running on my pc to modify and do at…
- User
make me gui app in python that can choose an app running on my pc to modify and do at least 20 things to them using buttons, make it look nice
- Assistant
make me gui app in python that can choose an app running on my pc to modify and do at least 20 things to them using buttons, make it look nice
Creating a Python GUI application that interacts with and modifies other running applications on your PC involves advanced operations that can potentially affect system stability and security. Please ensure you have the necessary permissions and understand the implications of manipulating other applications. Misusing such tools can lead to data loss, system crashes, or violations of software licenses.
Below is a step-by-step guide to creating a basic Python GUI application using Tkinter that can perform a variety of operations on running processes. This example will cover 20 functionalities such as listing running applications, terminating processes, changing window states, and more.
pip:pip install psutil pywin32 pillow
psutil: For process management.pywin32: For Windows-specific operations.Pillow: For handling images (optional, for enhancing the GUI).Below is the complete Python script for the GUI application:
import tkinter as tk
from tkinter import ttk, messagebox
import psutil
import subprocess
import win32gui
import win32con
import win32api
import win32process
import win32ui
import time
from PIL import Image, ImageTk
import os
# Function to get the list of running applications
def get_running_apps():
apps = []
for proc in psutil.process_iter(['pid', 'name']):
try:
HWND = win32gui.FindWindow(None, proc.info['name'])
if HWND:
apps.append((proc.info['pid'], proc.info['name']))
except:
continue
return apps
# Function to refresh the process list
def refresh_process_list():
process_listbox.delete(0, tk.END)
for pid, name in get_running_apps():
process_listbox.insert(tk.END, f"{pid} - {name}")
# Function to terminate a selected process
def terminate_process():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process to terminate.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
proc.terminate()
proc.wait(timeout=3)
messagebox.showinfo("Success", f"Process {proc.name()} terminated.")
refresh_process_list()
except Exception as e:
messagebox.showerror("Error", f"Failed to terminate process: {e}")
# Function to minimize a window
def minimize_window():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process to minimize.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
hwnd = win32gui.FindWindow(None, proc.name())
if hwnd:
win32gui.ShowWindow(hwnd, win32con.SW_MINIMIZE)
messagebox.showinfo("Success", f"Window for {proc.name()} minimized.")
else:
messagebox.showerror("Error", "Window not found.")
except Exception as e:
messagebox.showerror("Error", f"Failed to minimize window: {e}")
# Function to maximize a window
def maximize_window():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process to maximize.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
hwnd = win32gui.FindWindow(None, proc.name())
if hwnd:
win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
messagebox.showinfo("Success", f"Window for {proc.name()} maximized.")
else:
messagebox.showerror("Error", "Window not found.")
except Exception as e:
messagebox.showerror("Error", f"Failed to maximize window: {e}")
# Function to close a window
def close_window():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process to close.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
hwnd = win32gui.FindWindow(None, proc.name())
if hwnd:
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
messagebox.showinfo("Success", f"Window for {proc.name()} closed.")
else:
messagebox.showerror("Error", "Window not found.")
except Exception as e:
messagebox.showerror("Error", f"Failed to close window: {e}")
# Function to bring a window to front
def bring_to_front():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process to bring to front.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
hwnd = win32gui.FindWindow(None, proc.name())
if hwnd:
win32gui.SetForegroundWindow(hwnd)
messagebox.showinfo("Success", f"Window for {proc.name()} brought to front.")
else:
messagebox.showerror("Error", "Window not found.")
except Exception as e:
messagebox.showerror("Error", f"Failed to bring window to front: {e}")
# Function to take a screenshot of the window
def screenshot_window():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process to screenshot.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
hwnd = win32gui.FindWindow(None, proc.name())
if hwnd:
# Get window dimensions
left, top, right, bot = win32gui.GetClientRect(hwnd)
left, top = win32gui.ClientToScreen(hwnd, (left, top))
right, bot = win32gui.ClientToScreen(hwnd, (right, bot))
width = right - left
height = bot - top
# Create device context
hwin = win32gui.GetDesktopWindow()
hwindc = win32gui.GetWindowDC(hwin)
srcdc = win32ui.CreateDCFromHandle(hwindc)
memdc = srcdc.CreateCompatibleDC()
bmp = win32ui.CreateBitmap()
bmp.CreateCompatibleBitmap(srcdc, width, height)
memdc.SelectObject(bmp)
# Bit block transfer into memory device context
memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)
# Save bitmap to file
bmpinfo = bmp.GetInfo()
bmpstr = bmp.GetBitmapBits(True)
img = Image.frombuffer(
'RGB',
(bmpinfo['bmWidth'], bmpinfo['bmHeight']),
bmpstr, 'raw', 'BGRX', 0, 1)
img.save(f"{proc.name()}_screenshot.png")
# Free resources
win32gui.DeleteObject(bmp.GetHandle())
memdc.DeleteDC()
srcdc.DeleteDC()
win32gui.ReleaseDC(hwin, hwindc)
messagebox.showinfo("Success", f"Screenshot saved as {proc.name()}_screenshot.png.")
else:
messagebox.showerror("Error", "Window not found.")
except Exception as e:
messagebox.showerror("Error", f"Failed to take screenshot: {e}")
# Function to get process CPU usage
def get_cpu_usage():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
cpu = proc.cpu_percent(interval=1)
messagebox.showinfo("CPU Usage", f"Process {proc.name()} is using {cpu}% CPU.")
except Exception as e:
messagebox.showerror("Error", f"Failed to get CPU usage: {e}")
# Function to get process memory usage
def get_memory_usage():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
mem = proc.memory_info().rss / (1024 * 1024) # in MB
messagebox.showinfo("Memory Usage", f"Process {proc.name()} is using {mem:.2f} MB of RAM.")
except Exception as e:
messagebox.showerror("Error", f"Failed to get memory usage: {e}")
# Function to change window title
def change_window_title():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process.")
return
new_title = title_entry.get()
if not new_title:
messagebox.showwarning("Input Error", "Please enter a new title.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
hwnd = win32gui.FindWindow(None, proc.name())
if hwnd:
win32gui.SetWindowText(hwnd, new_title)
messagebox.showinfo("Success", f"Window title changed to '{new_title}'.")
refresh_process_list()
else:
messagebox.showerror("Error", "Window not found.")
except Exception as e:
messagebox.showerror("Error", f"Failed to change window title: {e}")
# Function to move window
def move_window():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process.")
return
try:
x = int(move_x_entry.get())
y = int(move_y_entry.get())
except ValueError:
messagebox.showwarning("Input Error", "Please enter valid integer coordinates.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
hwnd = win32gui.FindWindow(None, proc.name())
if hwnd:
win32gui.MoveWindow(hwnd, x, y, 800, 600, True) # Width and Height are set to 800x600
messagebox.showinfo("Success", f"Window moved to ({x}, {y}).")
else:
messagebox.showerror("Error", "Window not found.")
except Exception as e:
messagebox.showerror("Error", f"Failed to move window: {e}")
# Function to change window size
def resize_window():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process.")
return
try:
width = int(resize_width_entry.get())
height = int(resize_height_entry.get())
except ValueError:
messagebox.showwarning("Input Error", "Please enter valid integer dimensions.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
hwnd = win32gui.FindWindow(None, proc.name())
if hwnd:
rect = win32gui.GetWindowRect(hwnd)
x = rect[0]
y = rect[1]
win32gui.MoveWindow(hwnd, x, y, width, height, True)
messagebox.showinfo("Success", f"Window resized to {width}x{height}.")
else:
messagebox.showerror("Error", "Window not found.")
except Exception as e:
messagebox.showerror("Error", f"Failed to resize window: {e}")
# Function to toggle always on top
def toggle_always_on_top():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
hwnd = win32gui.FindWindow(None, proc.name())
if hwnd:
is_top = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
if not (is_top & win32con.WS_EX_TOPMOST):
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0,
win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
messagebox.showinfo("Success", f"{proc.name()} set to always on top.")
else:
win32gui.SetWindowPos(hwnd, win32con.HWND_NOTOPMOST, 0, 0, 0, 0,
win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
messagebox.showinfo("Success", f"{proc.name()} removed from always on top.")
else:
messagebox.showerror("Error", "Window not found.")
except Exception as e:
messagebox.showerror("Error", f"Failed to toggle always on top: {e}")
# Function to send keystrokes
def send_keystrokes():
selected = process_listbox.curselection()
keystrokes = keystrokes_entry.get()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process to send keystrokes.")
return
if not keystrokes:
messagebox.showwarning("Input Error", "Please enter keystrokes to send.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
import pyautogui
proc = psutil.Process(pid)
hwnd = win32gui.FindWindow(None, proc.name())
if hwnd:
win32gui.SetForegroundWindow(hwnd)
time.sleep(0.5) # Wait for the window to be in the foreground
pyautogui.typewrite(keystrokes)
messagebox.showinfo("Success", f"Keystrokes '{keystrokes}' sent to {proc.name()}.")
else:
messagebox.showerror("Error", "Window not found.")
except Exception as e:
messagebox.showerror("Error", f"Failed to send keystrokes: {e}")
# Function to send mouse clicks
def send_mouse_click():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process to send mouse clicks.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
import pyautogui
proc = psutil.Process(pid)
hwnd = win32gui.FindWindow(None, proc.name())
if hwnd:
win32gui.SetForegroundWindow(hwnd)
time.sleep(0.5)
pyautogui.click()
messagebox.showinfo("Success", f"Mouse click sent to {proc.name()}.")
else:
messagebox.showerror("Error", "Window not found.")
except Exception as e:
messagebox.showerror("Error", f"Failed to send mouse click: {e}")
# Function to duplicate a window
def duplicate_window():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process to duplicate.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
subprocess.Popen([proc.exe()])
messagebox.showinfo("Success", f"Duplicate of {proc.name()} launched.")
except Exception as e:
messagebox.showerror("Error", f"Failed to duplicate window: {e}")
# Function to suspend a process
def suspend_process():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process to suspend.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
proc.suspend()
messagebox.showinfo("Success", f"Process {proc.name()} suspended.")
except Exception as e:
messagebox.showerror("Error", f"Failed to suspend process: {e}")
# Function to resume a process
def resume_process():
selected = process_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process to resume.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
try:
proc = psutil.Process(pid)
proc.resume()
messagebox.showinfo("Success", f"Process {proc.name()} resumed.")
except Exception as e:
messagebox.showerror("Error", f"Failed to resume process: {e}")
# Function to change process priority
def change_priority():
selected = process_listbox.curselection()
priority = priority_var.get()
if not selected:
messagebox.showwarning("Selection Error", "Please select a process to change priority.")
return
process_info = process_listbox.get(selected[0]).split(" - ")
pid = int(process_info[0])
priority_mapping = {
"Idle": psutil.IDLE_PRIORITY_CLASS,
"Below Normal": psutil.BELOW_NORMAL_PRIORITY_CLASS,
"Normal": psutil.NORMAL_PRIORITY_CLASS,
"Above Normal": psutil.ABOVE_NORMAL_PRIORITY_CLASS,
"High": psutil.HIGH_PRIORITY_CLASS,
"Realtime": psutil.REALTIME_PRIORITY_CLASS,
}
try:
proc = psutil.Process(pid)
proc.nice(priority_mapping[priority])
messagebox.showinfo("Success", f"Priority of {proc.name()} set to {priority}.")
except Exception as e:
messagebox.showerror("Error", f"Failed to change priority: {e}")
# Function to refresh all information (placeholder for additional features)
def refresh_all():
refresh_process_list()
# Implement additional refresh functionalities if needed
# Initialize the main window
root = tk.Tk()
root.title("Process Manager")
root.geometry("800x600")
root.resizable(False, False)
# Set an icon (optional)
# root.iconbitmap('path_to_icon.ico')
# Create the main frame
main_frame = ttk.Frame(root, padding="10")
main_frame.pack(fill=tk.BOTH, expand=True)
# Process Listbox with Scrollbar
list_frame = ttk.LabelFrame(main_frame, text="Running Applications")
list_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=5, pady=5)
process_listbox = tk.Listbox(list_frame, width=40, selectmode=tk.SINGLE)
process_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=(0,5), pady=5)
scrollbar = ttk.Scrollbar(list_frame, orient=tk.VERTICAL, command=process_listbox.yview)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
process_listbox.configure(yscrollcommand=scrollbar.set)
# Control Panel
control_frame = ttk.Frame(main_frame, padding="10")
control_frame.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True, padx=5, pady=5)
# Buttons for various functionalities
buttons = [
("Terminate Process", terminate_process),
("Minimize Window", minimize_window),
("Maximize Window", maximize_window),
("Close Window", close_window),
("Bring to Front", bring_to_front),
("Take Screenshot", screenshot_window),
("Get CPU Usage", get_cpu_usage),
("Get Memory Usage", get_memory_usage),
("Change Window Title", change_window_title),
("Move Window", move_window),
("Resize Window", resize_window),
("Toggle Always on Top", toggle_always_on_top),
("Send Keystrokes", send_keystrokes),
("Send Mouse Click", send_mouse_click),
("Duplicate Window", duplicate_window),
("Suspend Process", suspend_process),
("Resume Process", resume_process),
("Change Priority", change_priority),
("Refresh List", refresh_all),
]
for idx, (text, command) in enumerate(buttons):
ttk.Button(control_frame, text=text, command=command).grid(row=idx, column=0, sticky="ew", pady=2)
# Additional Inputs
# Change Window Title
title_label = ttk.Label(control_frame, text="New Title:")
title_label.grid(row=8, column=1, sticky="w", padx=5)
title_entry = ttk.Entry(control_frame, width=25)
title_entry.grid(row=8, column=2, sticky="w", padx=5)
# Move Window
move_x_label = ttk.Label(control_frame, text="Move X:")
move_x_label.grid(row=9, column=1, sticky="w", padx=5)
move_x_entry = ttk.Entry(control_frame, width=10)
move_x_entry.grid(row=9, column=2, sticky="w", padx=5)
move_y_label = ttk.Label(control_frame, text="Move Y:")
move_y_label.grid(row=10, column=1, sticky="w", padx=5)
move_y_entry = ttk.Entry(control_frame, width=10)
move_y_entry.grid(row=10, column=2, sticky="w", padx=5)
# Resize Window
resize_width_label = ttk.Label(control_frame, text="Width:")
resize_width_label.grid(row=11, column=1, sticky="w", padx=5)
resize_width_entry = ttk.Entry(control_frame, width=10)
resize_width_entry.grid(row=11, column=2, sticky="w", padx=5)
resize_height_label = ttk.Label(control_frame, text="Height:")
resize_height_label.grid(row=12, column=1, sticky="w", padx=5)
resize_height_entry = ttk.Entry(control_frame, width=10)
resize_height_entry.grid(row=12, column=2, sticky="w", padx=5)
# Send Keystrokes
keystrokes_label = ttk.Label(control_frame, text="Keystrokes:")
keystrokes_label.grid(row=13, column=1, sticky="w", padx=5)
keystrokes_entry = ttk.Entry(control_frame, width=25)
keystrokes_entry.grid(row=13, column=2, sticky="w", padx=5)
# Change Priority Dropdown
priority_label = ttk.Label(control_frame, text="Priority:")
priority_label.grid(row=17, column=1, sticky="w", padx=5)
priority_var = tk.StringVar()
priority_dropdown = ttk.Combobox(control_frame, textvariable=priority_var)
priority_dropdown['values'] = ("Idle", "Below Normal", "Normal", "Above Normal", "High", "Realtime")
priority_dropdown.current(2) # Set default to Normal
priority_dropdown.grid(row=17, column=2, sticky="w", padx=5)
# Initial population of process list
refresh_process_list()
# Start the main loop
root.mainloop()
List Running Applications: Displays all currently running applications with their Process ID (PID) and name.
Terminate Process: Allows you to terminate a selected process safely.
Minimize/Maximize/Close Window: Controls the window state of the selected application.
Bring to Front: Brings the selected application's window to the foreground.
Take Screenshot: Captures a screenshot of the selected application's window and saves it as a PNG file.
Get CPU/Memory Usage: Retrieves and displays the CPU and memory usage of the selected process.
Change Window Title: Changes the title of the selected application's window.
Move Window: Moves the selected application's window to specified X and Y coordinates.
Resize Window: Resizes the selected application's window to specified width and height.
Toggle Always on Top: Toggles the "Always on Top" status of the selected application's window.
Send Keystrokes: Sends specified keystrokes to the selected application's window.
Send Mouse Click: Sends a mouse click to the selected application's window.
Duplicate Window: Launches a duplicate instance of the selected application.
Suspend/Resume Process: Suspends or resumes the selected process.
Change Priority: Changes the priority level of the selected process (e.g., Normal, High).
Refresh List: Refreshes the list of running applications to reflect current system state.
To make the application look nicer, you can:
Pillow library.ttk themes or switch to more advanced GUI frameworks like PyQt or Kivy for better aesthetics.pywin32. For other operating systems, additional modifications are necessary.Use this tool responsibly and ensure you comply with all relevant laws and software licenses.
Not yet included in a published release.