'My widget cannot be placed were I want because there was already another widget in tkinter

I made a GUI with tkinter, where you write your input and it creates and displays a QRcode of your in put. It is working correctly. But after writing an input ones next time the QRcode is getting placed below from where the previous QRcode image was. I think this is happening because the first label is not removed but the image disappears because the new QRcode has replaced the previous codes image. Can anyone tell me how do I make the new QRcode appear in the right positon or destroy the previous QRcode label so the new one is not placed below? also feel free to reply other solutions of my problem.

Python code:

from tkinter import *
from PIL import ImageTk, Image
from turtle import up

    import qrcode as qr
    
    window = Tk()
    
    window.geometry("300x350")
    
    user_entry = Entry(window, font='Helveticabold 30')
    user_entry.pack(side=TOP)
    
    def create_and_place_code():
        Code = user_entry.get()
        code = qr.make(Code)
        code.save('code.png')
        img = ImageTk.PhotoImage(Image.open("code.png"))
        code_img = Label(window, image=img)
        code_img.pack()
    
    user_button = Button(window, text='Generate', font=('Helvetica', 13), command=create_and_place_code)
    user_button.pack(anchor='center')
    
    window.mainloop()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source