In my program, I want to show an image in a canvas which I created before through a button command.
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()
答案 0 :(得分:0)
我使用方法.show()
找到解决方案 plt.show()