Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import tkinter as tk
- from tkinter import filedialog
- from PIL import Image
- class ImageConverterApp:
- def __init__(self, root):
- self.root = root
- self.root.title("Image Converter")
- self.root.geometry("650x250")
- self.root.resizable(False, False)
- self.root.configure(background="white")
- self.file_path = None
- self.choose_button = tk.Button(
- self.root, text="Escolher arquivo", font=("Arial", 12), command=self.choose_file
- )
- self.choose_button.pack(pady=20)
- self.convert_button = tk.Button(
- self.root, text="Converter", font=("Arial", 12), command=self.convert_image, state=tk.DISABLED
- )
- self.convert_button.pack(pady=20)
- self.drop_label = tk.Label(
- self.root, text="Nenhum arquivo selecionado", font=("Arial", 12), bg="white"
- )
- self.drop_label.pack(pady=10)
- def choose_file(self):
- self.file_path = filedialog.askopenfilename(filetypes=[("WebP Image", "*.webp")])
- if self.file_path:
- self.drop_label.config(text="Arquivo selecionado: " + os.path.basename(self.file_path))
- self.convert_button.config(state=tk.NORMAL)
- else:
- self.drop_label.config(text="Nenhum arquivo selecionado")
- self.convert_button.config(state=tk.DISABLED)
- def convert_image(self):
- save_path = filedialog.asksaveasfilename(
- defaultextension=".png", filetypes=[("PNG Image", "*.png"), ("JPEG Image", "*.jpg")]
- )
- if save_path:
- try:
- image = Image.open(self.file_path)
- image.save(save_path)
- self.drop_label.config(text="Conversão concluída! Arquivo salvo como " + os.path.basename(save_path))
- except:
- self.drop_label.config(text="Erro ao converter a imagem!")
- else:
- self.drop_label.config(text="Operação cancelada!")
- root = tk.Tk()
- root.title("Image Converter")
- root.geometry("800x600")
- root.resizable(False, False)
- root.configure(background="white")
- app = ImageConverterApp(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement