点击任意按钮,上一个按钮插入的图片仍然存在

问题遇到的现象和发生背景
用代码块功能插入代码,请勿粘贴截图
import tkinter

import cv2
from PIL import Image, ImageTk

topwin = tkinter.Tk()         #创建顶层窗口
topwin.geometry('1000x600')     #初始化窗口大小
topwin.title('实验一') #设置窗口标题

img_open = Image.open('computer.jpg')
# img = ImageTk.PhotoImage(img_open)
img = ImageTk.PhotoImage(img_open.resize((250,300),Image.ANTIALIAS))

def SoucerImg():
    label = tkinter.Label(topwin,
                          text='Rice原图',
                          image=img,
                          font=('黑体', 20),
                          fg='red',  # 字体颜色
                          compound=tkinter.BOTTOM  # 设置文本和图像的混合模式
                          )
    label.pack(side=tkinter.LEFT)



def Laplacianshow():
    label = tkinter.Label(topwin,
                          text='Laplacian算子',
                          image=imgout_1,
                          font=('黑体', 20),
                          fg='red',  # 字体颜色
                          compound=tkinter.BOTTOM  # 设置文本和图像的混合模式
                          )
    label.pack(side=tkinter.LEFT)

def Laplacian():
    # 灰度化处理图像
    grayImage = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
    blurred = cv2.GaussianBlur(grayImage, (3, 3), 0)
    dst = cv2.Laplacian(grayImage, cv2.CV_16S, ksize=3)
    Laplacian = cv2.convertScaleAbs(dst)
    cv2.imwrite('Laplacianimg.png',Laplacian)

def LoG():
    # 灰度化处理图像
    grayImage = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
    blurred = cv2.GaussianBlur(grayImage, (3, 3), 0)
    # LoG算法
    dst1 = cv2.Laplacian(blurred, cv2.CV_16S, ksize=3)
    LoG = cv2.convertScaleAbs(dst1)
    cv2.imwrite('LoGimg.png',LoG)

def LoGshow():
    label = tkinter.Label(topwin,
                          text='LoG算子',
                          image=imgout_2,
                          font=('黑体', 20),
                          fg='red',  # 字体颜色
                          compound=tkinter.BOTTOM  # 设置文本和图像的混合模式
                          )
    label.pack(side=tkinter.LEFT)

def Canny():
    # 灰度化处理图像
    grayImage = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
    blurred = cv2.GaussianBlur(grayImage, (3, 3), 0)
    # LoG算法
    dst2 = cv2.Canny(blurred, 20, 40)
    Canny = cv2.convertScaleAbs(dst2)
    cv2.imwrite('Cannyimg.png',Canny)

def Cannyshow():
    label = tkinter.Label(topwin,
                          text='Canny算子',
                          image=imgout_3,
                          font=('黑体', 20),
                          fg='red',  # 字体颜色
                          compound=tkinter.BOTTOM  # 设置文本和图像的混合模式
                          )
    label.pack(side=tkinter.LEFT)


# 读取图像
img1 = cv2.imread('computer.jpg')
lenna_img = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)# 灰度化处理图像
Laplacian()
imgout1=Image.open("Laplacianimg.png")
imgout_1 = ImageTk.PhotoImage(imgout1.resize((250,300),Image.ANTIALIAS))
LoG()
imgout2=Image.open("LoGimg.png")
imgout_2 = ImageTk.PhotoImage(imgout2.resize((250,300),Image.ANTIALIAS))
Canny()
imgout3=Image.open("LoGimg.png")
imgout_3 = ImageTk.PhotoImage(imgout3.resize((250,300),Image.ANTIALIAS))





button1 = tkinter.Button(topwin, text ="原图",command = SoucerImg,width=10)
button1.place(x=0,y=0)

button2 = tkinter.Button(topwin, text ="Laplacian算子",command = Laplacianshow,width=10)
button2.place(x=80,y=0)

button3 = tkinter.Button(topwin, text ="LoG算子",command = LoGshow,width=10)
button3.place(x=160,y=0)

button4 = tkinter.Button(topwin, text ="Canny算子",command = Cannyshow,width=10)
button4.place(x=240,y=0)



button5=tkinter.Button(topwin,text='退出',command=topwin.quit,width=10)
button5.place(x=320,y=0)



topwin.mainloop()#显示窗口

运行结果及报错内容

img

我想要达到的结果

按任意按钮只显示当前按钮下插入的图片

简单啊,首先布局要想好,看你的意思,应该是原图是位置不动,其他三个效果图是按哪个就显示哪个对吧?那我们就需要先放两个空白的label占位,然后点击按钮的时候往label里塞图片和文字就可以了。增加两个label组件,并把那几个按钮对应的函数改成下面这样:

label1 = tkinter.Label(topwin,
                          font=('黑体', 20),
                          fg='red',  # 字体颜色
                          compound=tkinter.BOTTOM  # 设置文本和图像的混合模式
                          )
label1.pack(side=tkinter.LEFT)
label2 = tkinter.Label(topwin,
                          font=('黑体', 20),
                          fg='red',  # 字体颜色
                          compound=tkinter.BOTTOM  # 设置文本和图像的混合模式
                          )
label2.pack(side=tkinter.LEFT)
def SoucerImg():
    label1['text']='Rice原图'
    label1['image']=img
 
def Laplacianshow():
    label2['text']='Laplacian算子'
    label2['image']=imgout_1

def LoGshow():
    label2['text']='LoG算子'
    label2['image']=imgout_2
 
def Cannyshow():
    label2['text']='Canny算子'
    label2['image']=imgout_3

那你实现一个函数点击上一步,把显示图片的函数清除了不显示不就完了,你看你主要显示图片的函数是啥,肯定有对应的方法不显示或者类似的方法