image in canvas ( tkinter ) is not displayed when i use a button

时间:2016-04-04 17:48:33

标签: python tkinter tkinter-canvas

In my program, I want to show an image in a canvas which I created before through a button command.

Here is my code:

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



def dessiner ():



    # open the image 
    image = Image.open("img1.png")
    image = image.resize( (400,300), Image.ANTIALIAS) # resize the image to be show in the canvas
    img = ImageTk.PhotoImage(image)
    canvas.create_image(200, 175, image = img)



    return 0

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

1 个答案:

答案 0 :(得分:0)

我使用方法.show()

找到解决方案
 plt.show()
相关问题