Tkinter: Does anyone know how to change a button into a image?

This is my code for the button that opens an app:

Modules:

import tkinter as tk
from tkinter import *
from PIL import ImageTk, Image
from subprocess import Popen

Importing Image:

path = ("C:PicturesGoogleLogo.png")
img = Image.open(path)
img = img.resize((96, 96), Image.ANTIALIAS)
img = ImageTk.PhotoImage(img)

Generic Canvas Button:

def openCalc():
    Popen("calc.exe")

openCalcWin = tk.Button(text='Calculator', command=openCalc, bg="Grey", height = 6, width = 10)
canvas.create_window(1167,714, window=openCalcWin)

What I have Tried:

I attempted to make the background of the button into an image by using bg or img. But this just creates an tiny image logo that can’t be clicked. Indicating that there was an error loading the image, but there was no error code or anything in the IDLE Shell.

There was other attempts of code that I forgot, but most of them ends up the same: no button appeared and no error code.

Edit:

import tkinter as tk
from PIL import ImageTk, Image
from subprocess import Popen

##Application Window:
root=tk.Tk()
root.title("Virtual Desktop")
root.resizable(False, False)

#Determine Window Resolution
canvas = tk.Canvas(root, width=1280, height=780, bg="#263D42")
canvas.pack()

#Importing Calulator Image
path = ("C:PicturesCalcLogo.png")
img = Image.open(path)
img = img.resize((96, 96), Image.ANTIALIAS)
img = ImageTk.PhotoImage(img)


#Calculator Button
def openCalc():
    Popen("calc.exe")

openCalcWin = tk.Button(text='Calculator', command=openCalc, bg="Grey", height = 6, width = 10)
canvas.create_window(1167,714, window=openCalcWin)

Answer

The following works for me. The most important change was to specify an image= keyword argument, when creating the Button.

The other thing I noted was the:

path = ("C:PicturesCalcLogo.png")

you had. The parentheses are unnecessary (but don’t hurt), however you need to add an r prefix to all strings containing back-slash characters like paths on Windows.

path = r"C:PicturesCalcLogo.png"

or just use forward-slashes (which work fine on Windows):

path = "C:/Pictures/CalcLogo.png"

Full code:

import tkinter as tk
from PIL import ImageTk, Image
from subprocess import Popen

##Application Window:
root=tk.Tk()
root.title("Virtual Desktop")
root.resizable(False, False)

#Determine Window Resolution
canvas = tk.Canvas(root, width=1280, height=780, bg="#263D42")
canvas.pack()

#Importing Calulator Image
path = "8-ball.png"  # My own image.
img = Image.open(path)
img = img.resize((96, 96), Image.ANTIALIAS)
img = ImageTk.PhotoImage(img)


#Calculator Button
def openCalc():
    Popen("calc.exe")

openCalcWin = tk.Button(text='Calculator', command=openCalc, bg="Grey",
                        image=img)
canvas.create_window(1167,714, window=openCalcWin)

root.mainloop()