I seem to be having some problems with this code I created. I am trying to get two buttons to create images on my Tkinter canvas.
For some reason my buttons when clicked do NOT RETURN ANY ERROR however they do not show the images either in the canvas.
Can anyone help me figure out what the error in my code is? Thanks in advance!
Note that when the code to create both images is run outside the defined functions it does succesfully create the images on the canvas, the problem is that the button does not execute the command correctly
import tkinter
from tkinter import ttk
from tkinter import *
import PIL.Image
import PIL.ImageTk
root = Tk()
canvas = Canvas(root)
canvas.pack()
canvas.config(width=300, height= 500,background = 'white')
def previewpng():
photo = PhotoImage( file = 'C:/Users/Admin/Documents/logo.png')
png_preview = canvas.create_image(150,150, image = photo)
def preview():
Imagetif = PIL.Image.open( "C:/Users/Admin/Documents/sampledata.tif")
Im = PIL.ImageTk.PhotoImage(Imagetif)
preview = canvas.create_image( relx = 0, rely= 0, image = Im )
#creating buttons
button= ttk.Button (root, text= 'View preview of PNG')
button.pack()
button.config( command = previewpng )
button2= ttk.Button (root, text= 'View Preview of Tif file')
button2.pack()
button2.config( command = preview )
root.mainloop()