我用Tkinter在Python中构建了一个GUI应用程序,该应用程序会在单击按钮时生成并显示一张图片。该图片是通过matplotlib的savefig("displayimage.png")命令在与我的应用程序.py文件相同的文件夹中生成的。第一次单击按钮时,它可以正常显示图片,但第二次单击按钮时,新的图片会覆盖旧的图片。我尝试使用os.remove("displayimage.png")从文件夹中删除现有的图片,但这并没有起到作用。你知道为什么它不会覆盖旧的图片而是重叠吗?顺便说一下,我尝试将其保存为.jpg文件,但结果相同。谢谢提前帮助。代码如下:
# make a square figure and axes
figure(1, figsize=(6, 6))
ax = axes([0.1, 0.1, 0.8, 0.8])
# The slices will be ordered and plotted counter-clockwise.
labels = words
fracs = percent
colors = ('yellowgreen', 'gold', 'lightskyblue', 'lightcoral', 'blue', 'yellow', 'cyan', 'pink',
'purple', 'green', 'magenta', 'orange')
pie(fracs, labels=labels, colors=colors,
autopct='%.1f%%', shadow=True, startangle=90)
title("Most used words", fontsize=20)
savefig('senalyzed_piechart.png',dpi=80)