How to Convert PNG to JPG using Python

Subscribe to my newsletter and never miss my upcoming articles

You need to install Pillow package to convert PNG to JPG.

pip3 install Pillow

Then run below code and your PNG to JPG Tool is ready.

import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
from PIL import Image

root = tk.Tk()
canvas1 = tk.Canvas(root, width=300, height=250, bg='gray', relief = 'raised')

label1 = tk.Label(root, text='PNG to JPG Tool', bg='gray')
label1.config(font=('helvetica', 20))

def getPNG():
    global im1
    import_file_path = filedialog.askopenfilename()
    im1 ='RGB')

browseButton_PNG = tk.Button(text="   Import PNG file  ", command=getPNG)

def convertToJPG():
    global im1

    export_file_path = filedialog.asksaveasfilename(defaultextension='.jpg')

saveAsButton_JPG = tk.Button(text='Convert PNG to JPG', command=convertToJPG)
canvas1.create_window(150, 180, window=saveAsButton_JPG)


If any doubt, please comment below.

Watch the full course on Python:

No Comments Yet