πŸ”₯ Ultimate Python Trick You MUST Try! (Shocking Hack Inside)

 Demo :


Click Video πŸ‘‡πŸ‘‡πŸ‘‡




Code :


import os

import tkinter as tk

from tkinter import filedialog, messagebox

from PIL import Image


# Function to convert image

def convert_image():

    input_path = filedialog.askopenfilename(title="Select Image", filetypes=[("Image Files", "*.png;*.jpg;*.jpeg;*.webp")])

    

    if not input_path:

        return

    

    output_format = format_var.get()  # Get selected format

    

    if output_format not in ["PNG", "JPG", "WEBP"]:

        messagebox.showerror("Error", "Invalid format selected!")

        return

    

    try:

        image = Image.open(input_path)


        # Ensure output directory exists

        output_dir = os.path.join(os.getcwd(), "output")

        if not os.path.exists(output_dir):

            os.makedirs(output_dir)


        # Define output file path

        file_name = os.path.splitext(os.path.basename(input_path))[0] + f"_converted.{output_format.lower()}"

        output_path = os.path.join(output_dir, file_name)


        # Convert and save the image

        image.save(output_path, output_format.upper())

        messagebox.showinfo("Success", f"Image converted successfully!\nSaved at: {output_path}")

    

    except Exception as e:

        messagebox.showerror("Error", f"Failed to convert image: {e}")


# Create GUI window

root = tk.Tk()

root.title("Image Converter")

root.geometry("400x300")


# Label

tk.Label(root, text="Select Format to Convert:", font=("Arial", 12)).pack(pady=10)


# Dropdown for format selection

format_var = tk.StringVar(value="PNG")

formats = ["PNG", "JPG", "WEBP"]

format_menu = tk.OptionMenu(root, format_var, *formats)

format_menu.pack(pady=5)


# Convert Button

convert_btn = tk.Button(root, text="Select & Convert Image", command=convert_image, font=("Arial", 12), bg="blue", fg="white")

convert_btn.pack(pady=20)


# Run Tkinter Loop

root.mainloop()

Comments

Popular posts from this blog

Is This News Real or Fake? πŸ€– AI Exposes the Truth | FuzzuTech Python App Demo

🚨 Python Intrusion Detection System (IDS) – Real-Time ML + Tkinter GUI Project | FuzzuTech

πŸš€ Simple Login & Registration System in Python Tkinter πŸ“±