在我的程序中,我想在画布中显示一个图像,该图像是我之前通过按钮命令创建的。
这是我的代码:
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()
我使用方法.show()找到解决方案
plt.show()