0

I want to display an image in a canvas through a button command, but it doesn't work !

this is the code:

from Tkinter import Tk,Button,Canvas,PhotoImage
from PIL import Image, ImageTk



def plot ():

    

    
    image = Image.open("img1.png")
    image = image.resize( (400,300), Image.ANTIALIAS) 
    img = ImageTk.PhotoImage(image)
    canvas.create_image(200, 175, image = img)
    
    

    return 0

tkk = Tk()
canvas = Canvas(tkk, \
width =400, height =650, \
bg="light yellow")
canvas.pack(side ="right")
button_plot = Button(tkk, text = "dessiner", command = dessiner, width = 50, fg = "red")
button_plot.pack()
mw.mainloop()

I tried to use : TopLevel() in my function ' plot()' but i got the same result which is a canvas without any image !

Community
  • 1
  • 1
  • Possible duplicate of [Python Tkinter : gif image in a canvas](http://stackoverflow.com/questions/16424091/python-tkinter-gif-image-in-a-canvas) – Bryan Oakley Apr 07 '16 at 11:33

1 Answers1

0

Finally, i find the solution which is adding this command in the end of the function plot():

  import matplotlib.pyplot as plt

  canvas.create_image(200, 175, image = img)
  plt.show()