Close Menu
Techs Slash

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Why Weekly House Cleaning Services and Moving In Cleaning Are Game-Changers for Singapore Homes

    July 12, 2025

    Leverage 1:500 vs 1:100 – How It Works and When to Use It?

    July 12, 2025

    How To Develop A Strategy That Works On Khelostar

    July 10, 2025
    Facebook X (Twitter) Instagram
    Techs Slash
    • Home
    • News
      • Tech
      • Crypto News
      • Cryptocurrency
    • Entertainment
      • Actors
      • ANGEL NUMBER
      • Baby Names
      • Beauty
      • beauty-fashion
      • facebook Bio
      • Fitness
      • Dubai Tour
    • Business
      • Business Names
    • Review
      • Software
      • Smartphones & Apps
    • CONTRIBUTION
    Facebook X (Twitter) Instagram
    Techs Slash
    Home»News»How to Convert JPG to PNG using Python Tkinter Pillow Image Library
    News

    How to Convert JPG to PNG using Python Tkinter Pillow Image Library

    Ranveer KumarBy Ranveer KumarOctober 6, 2022No Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email

    Warning: Trying to access array offset on value of type bool in /home/cadesimu/techsslash.com/wp-content/themes/smart-mag/partials/single/featured.php on line 78
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Today we will talk about this significant subject by means of this article How to Change JPG over completely to PNG utilizing Python Tkinter Pad Picture Library. We want to believe that you like this article.

    How to Convert JPG to PNG using Python Tkinter Pillow Image Library

    pip install tk
    pip install Pillow
    # --  IMAGE CONVERTER PROGRAM  -- #
    
    from tkinter import *
    from PIL import Image, ImageTk
    from tkinter import filedialog as fd #It will contain open and save dialog boxes
    
    '''Functions which are being used in the program (To convert JPG to PNG and Vice Versa)'''
    def jpgtopng():
        root.config(bg='#badc57')
        def getjpgfile():
            global pic
            file_path = fd.askopenfilename()
            pic=Image.open(file_path)   #It will open the file and will store it in pic variable (.open and .save are the methods of Image of PIL Module)
    
        def savepngfile():
            global pic
            export_file_path = fd.asksaveasfilename(defaultextension='.png',filetypes= [('Image (.png file)','.png')] )
            pic.save(export_file_path)      #It will save the file to the specified path
    
        global Head
        imagelabel.destroy()
        f1.destroy()
        Head.destroy()
        Head=Label(text='JPG To PNG Converter',font='Lucida 20 bold',bg='black',fg='#F4C724',padx=5,pady=5)
        Head.pack(pady=10)
        #To get jpg file
        browse_jpg = Button(text="      Import JPG File     ", bg='#BB2CD9', fg='white', font=('helvetica', 15, 'bold'),command=getjpgfile)
        browse_jpg.pack(pady=20)
        #To save jpg file
        save_jpg=Button(text='  Convert JPG To PNG  ', bg='#BB2CD9', fg='white', font=('helvetica', 15, 'bold'),command=savepngfile)
        save_jpg.pack(pady=10)
    
        #Image in bottom
        bottom_pic=Image.open('Images/jtop.jpg')
        bottom_pic=bottom_pic.resize((400,250),Image.ANTIALIAS)
        bg_pic=ImageTk.PhotoImage(bottom_pic)
        img_label=Label(root,image=bg_pic)
        img_label.image=bg_pic  #It will make a reference or keep a reference
        img_label.pack(side=BOTTOM,pady=40)
    
        #Close Button
        close=Button(text='Close',command=root.destroy,bg='black',fg='white',font='11')
        close.place(x=205,y=422)
    
    
    
    def pngtojpg():
        root.config(bg='#67E6DC')
        def getpngfile():
            global pic
            file_location=fd.askopenfilename()
            pic=Image.open(file_location)       #It will store the selected file in pic variable 
            pic=pic.convert('RGB')  #It will covert the file from RGBA to RGB coz PNG files have some transparency or alpha value so we need to remove that to make it a JPG file.
    
        def savejpgfile():
            global pic
            export_file_location = fd.asksaveasfilename(defaultextension='.jpg')
            pic.save(export_file_location)  #It will save the image to a specified location
    
        global Head
        imagelabel.destroy()
        f1.destroy()
        Head.destroy()
        Head=Label(text='PNG To JPG Converter',font='Lucida 20 bold',bg='black',fg='#F4C724',padx=5,pady=5)
        Head.pack(pady=10)
        #To get jpg file
        browse_jpg = Button(text="      Import PNG File     ", bg='#2B2B52', fg='white', font=('helvetica', 15, 'bold'),command=getpngfile)
        browse_jpg.pack(pady=20)
        #To save jpg file
        save_jpg=Button(text='  Convert PNG To JPG  ', bg='#2B2B52', fg='white', font=('helvetica', 15, 'bold'),command=savejpgfile)
        save_jpg.pack(pady=10)
    
        #Image in bottom
        bottom_pic=Image.open('Images/ptoj.jpg')
        bottom_pic=bottom_pic.resize((400,250),Image.ANTIALIAS)
        bg_pic=ImageTk.PhotoImage(bottom_pic)
        img_label=Label(root,image=bg_pic)
        img_label.image=bg_pic  #It will make a reference or keep a reference
        img_label.pack(side=BOTTOM,pady=40)
    
        #Close Button
        close=Button(text='Close',command=root.destroy,bg='black',fg='white',font='11')
        close.place(x=205,y=422)
    
    ''' Events of buttons '''
    def jtopenter(event):
        jtop.config(bg='black',fg='white')
    def jtopleave(event):
        jtop.config(bg='white',fg='black')
    
    def ptojenter(event):
        ptoj.config(bg='black',fg='white')
    def ptojleave(event):
        ptoj.config(bg='white',fg='black')
    
    
    '''Main GUI Program'''
    
    root=Tk()
    root.title('Image Converter')
    root.wm_iconbitmap('Images/icon/pic.ico')
    root.geometry('450x480')
    
    
    '''Creating Main Window :'''
    
    #Heading of GUI
    Head=Label(text='Image Converter',font='Lucida 20 bold',bg='black',fg='#F4C724',padx=5,pady=5)
    Head.pack(pady=10)
    
    #Buttons
    f1=Frame(root)
    jtop=Button(f1,text='JPG To PNG',font='arial 15 bold',command=jpgtopng)
    jtop.pack(side='left',padx=40)
    jtop.bind('<Enter>',jtopenter)
    jtop.bind('<Leave>',jtopleave)
    ptoj=Button(f1,text='PNG To JPG',font='arial 15 bold',command=pngtojpg)
    ptoj.pack(padx=40)
    ptoj.bind('<Enter>',ptojenter)
    ptoj.bind('<Leave>',ptojleave)
    f1.pack(pady=20)
    
    #Image
    img=Image.open('Images/bg_pic.png')
    img=img.resize((300,275),Image.ANTIALIAS)
    bgpic=ImageTk.PhotoImage(img)
    imagelabel=Label(image=bgpic)
    imagelabel.pack(pady=10)
    
    #Status Bar
    sbar=Label(text='By Logical Coder',font='Helvetica 10 bold',relief=SUNKEN,anchor='w',padx=10)
    sbar.pack(side=BOTTOM,fill=X)
    
    
    root.mainloop()

    Final Words

    Step by step instructions to Switch JPG over completely to PNG utilizing Python Tkinter Cushion Picture Library We found out about this obviously through this article. Also, assuming you enjoyed this article kindly offer it with your companion.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Ranveer Kumar
    • Website

    Related Posts

    What Happens When Algorithms Violate Consumer Rights?

    May 31, 2025

    Ludy Tatiana: A Pawn or the Queen?

    April 17, 2024

    Adult Wiseplay Lists Free and Updated

    March 28, 2024
    Leave A Reply Cancel Reply

    Top Posts

    Sapne Me Nahane Ka Matlab

    March 18, 2024

    Sapne Me Nagn Stri Dekhna

    March 18, 2024

    Self Reliance: Release Date, Cast, Plot, Trailer, and More Information

    March 18, 2024

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    ABOUT TECHSSLASH

    Welcome to Techsslash! We're dedicated to providing you with the best of technology, finance, gaming, entertainment, lifestyle, health, and fitness news, all delivered with dependability.

    Our passion for tech and daily news drives us to create a booming online website where you can stay informed and entertained.

    Enjoy our content as much as we enjoy offering it to you

    Most Popular

    Sapne Me Nahane Ka Matlab

    March 18, 2024

    Sapne Me Nagn Stri Dekhna

    March 18, 2024

    Self Reliance: Release Date, Cast, Plot, Trailer, and More Information

    March 18, 2024
    CONTACT DETAILS

    Phone: +92-302-743-9438
    Email: contact@serpinsight.com

    Our Recommendation

    Here are some helpfull links for our user. hopefully you liked it.

    Techs Slash
    Facebook X (Twitter) Instagram Pinterest
    • Home
    • About us
    • contact us
    • Affiliate Disclosure
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • Write for us
    • Daman Game
    © 2025 Techsslash. All Rights Reserved

    Type above and press Enter to search. Press Esc to cancel.