Why this tkinter GUI code behaves differently when inside a function?

This generate_GUI1 function does not generate some buttons on the GUI


# This file was generated by the Tkinter Designer by Parth Jadhav
# https://github.com/ParthJadhav/Tkinter-Designer


from pathlib import Path

# from tkinter import *
# Explicit imports to satisfy Flake8
from tkinter import Tk, Canvas, Entry, Text, Button, PhotoImage
import os

CURRENT_PATH = os.getcwd()

OUTPUT_PATH = Path(__file__).parent
ASSETS_PATH = OUTPUT_PATH / Path(CURRENT_PATH + r"assetsframe1")

window = Tk()

window.geometry("1000x729")
window.configure(bg = "#4B0082")

def relative_to_assets(path: str) -> Path:
    return ASSETS_PATH / Path(path)


def generate_GUI1(Frame):


    canvas = Canvas(
    Frame,
    bg = "#4B0082",
    height = 729,
    width = 1000,
    bd = 0,
    highlightthickness = 0,
    relief = "ridge"
    )

    canvas.place(x = 0, y = 0)
    canvas.create_rectangle(
    248.0,
    0.0,
    1000.0,
    729.0,
    fill="#D9D9D9",
    outline="")

    canvas.create_rectangle(
    353.0,
    198.0,
    841.0,
    500.0,
    fill="#00827A",
    outline="")

    canvas.create_rectangle(
    353.0,
    149.0,
    841.0,
    198.0,
    fill="#210082",
    outline="")

    canvas.create_text(
    363.0,
    164.0,
    anchor="nw",
    text="VarianteID",
    fill="#FFFFFF",
    font=("Inter ExtraLightItalic", 15 * -1)
    )

    canvas.create_text(
    461.0,
    164.0,
    anchor="nw",
    text="ProductoID",
    fill="#FFFFFF",
    font=("Inter ExtraLightItalic", 15 * -1)
    )

    canvas.create_text(
    570.0,
    164.0,
    anchor="nw",
    text="TallaID",
    fill="#FFFFFF",
    font=("Inter ExtraLightItalic", 15 * -1)
    )

    canvas.create_text(
    647.0,
    164.0,
    anchor="nw",
    text="ColorID",
    fill="#FFFFFF",
    font=("Inter ExtraLightItalic", 15 * -1)
    )

    canvas.create_text(
    742.0,
    164.0,
    anchor="nw",
    text="SKU",
    fill="#FFFFFF",
    font=("Inter ExtraLightItalic", 15 * -1)
    )

    button_image_1 = PhotoImage(
    file=relative_to_assets("button_1.png"))
    button_1 = Button(
    image=button_image_1,
    borderwidth=0,
    highlightthickness=0,
    command=lambda: print("button_1 clicked"),
    relief="flat"
    )
    button_1.place(
    x=353.0,
    y=87.0,
    width=185.0,
    height=36.0
    )

    button_image_2 = PhotoImage(
    file=relative_to_assets("button_2.png"))
    button_2 = Button(
    image=button_image_2,
    borderwidth=0,
    highlightthickness=0,
    command=lambda: print("button_2 clicked"),
    relief="flat"
    )
    button_2.place(
    x=380.0,
    y=542.0,
    width=113.0,
    height=50.0
    )

    button_image_3 = PhotoImage(
    file=relative_to_assets("button_3.png"))
    button_3 = Button(
    image=button_image_3,
    borderwidth=0,
    highlightthickness=0,
    command=lambda: print("button_3 clicked"),
    relief="flat"
    )
    button_3.place(
    x=536.0,
    y=543.0,
    width=118.0,
    height=50.0
    )

    button_image_4 = PhotoImage(
    file=relative_to_assets("button_4.png"))
    button_4 = Button(
    image=button_image_4,
    borderwidth=0,
    highlightthickness=0,
    command=lambda: print("button_4 clicked"),
    relief="flat"
    )
    button_4.place(
    x=704.0,
    y=543.0,
    width=118.0,
    height=50.0
    )

    canvas.create_rectangle(
    0.0,
    0.0,
    248.0,
    729.0,
    fill="#008282",
    outline="")

    image_image_1 = PhotoImage(
    file=relative_to_assets("image_1.png"))
    image_1 = canvas.create_image(
    115.0,
    89.0,
    image=image_image_1
    )

    button_image_5 = PhotoImage(
    file=relative_to_assets("button_5.png"))
    button_5 = Button(
    image=button_image_5,
    borderwidth=0,
    highlightthickness=0,
    command=lambda: print("button_5 clicked"),
    relief="flat"
    )
    button_5.place(
    x=25.0,
    y=480.0,
    width=198.0,
    height=45.0
    )

    button_image_6 = PhotoImage(
    file=relative_to_assets("button_6.png"))
    button_6 = Button(
    image=button_image_6,
    borderwidth=0,
    highlightthickness=0,
    command=lambda: print("button_6 clicked"),
    relief="flat"
    )
    button_6.place(
    x=25.0,
    y=171.0,
    width=198.0,
    height=51.0
    )

    button_image_7 = PhotoImage(
    file=relative_to_assets("button_7.png"))
    button_7 = Button(
    image=button_image_7,
    borderwidth=0,
    highlightthickness=0,
    command=lambda: print("button_7 clicked"),
    relief="flat"
    )
    button_7.place(
    x=25.0,
    y=253.0,
    width=198.0,
    height=44.0
    )

    button_image_8 = PhotoImage(
    file=relative_to_assets("button_8.png"))
    button_8 = Button(
    image=button_image_8,
    borderwidth=0,
    highlightthickness=0,
    command=lambda: print("button_8 clicked"),
    relief="flat"
    )
    button_8.place(
    x=25.0,
    y=328.0,
    width=198.0,
    height=45.0
    )

    button_image_9 = PhotoImage(
    file=relative_to_assets("button_9.png"))
    button_9 = Button(
    image=button_image_9,
    borderwidth=0,
    highlightthickness=0,
    command=lambda: print("button_9 clicked"),
    relief="flat"
    )
    button_9.place(
    x=25.0,
    y=404.0,
    width=198.0,
    height=45.0
    )

    button_image_10 = PhotoImage(
    file=relative_to_assets("button_10.png"))
    button_10 = Button(
    image=button_image_10,
    borderwidth=0,
    highlightthickness=0,
    command=lambda: print("button_10 clicked"),
    relief="flat"
    )
    button_10.place(
    x=25.0,
    y=556.0,
    width=198.0,
    height=45.0
    )

    button_image_11 = PhotoImage(
    file=relative_to_assets("button_11.png"))
    button_11 = Button(
    image=button_image_11,
    borderwidth=0,
    highlightthickness=0,
    command=lambda: print("button_11 clicked"),
    relief="flat"
    )
    button_11.place(
    x=25.0,
    y=632.0,
    width=198.0,
    height=45.0
    )
    return


generate_GUI1(window)


window.resizable(False, False)
window.mainloop()

This is not what I expected, but for some reason by writing the code inside the function outside, now I get all the buttons that must appears in the GUI.


from pathlib import Path

# from tkinter import *
# Explicit imports to satisfy Flake8
from tkinter import Tk, Canvas, Entry, Text, Button, PhotoImage
import os

CURRENT_PATH = os.getcwd()

OUTPUT_PATH = Path(__file__).parent
ASSETS_PATH = OUTPUT_PATH / Path(CURRENT_PATH + r"assetsframe1")

window = Tk()

window.geometry("1000x729")
window.configure(bg = "#4B0082")

def relative_to_assets(path: str) -> Path:
    return ASSETS_PATH / Path(path)



canvas = Canvas(
window,
bg = "#4B0082",
height = 729,
width = 1000,
bd = 0,
highlightthickness = 0,
relief = "ridge"
)

canvas.place(x = 0, y = 0)
canvas.create_rectangle(
248.0,
0.0,
1000.0,
729.0,
fill="#D9D9D9",
outline="")

canvas.create_rectangle(
353.0,
198.0,
841.0,
500.0,
fill="#00827A",
outline="")

canvas.create_rectangle(
353.0,
149.0,
841.0,
198.0,
fill="#210082",
outline="")

canvas.create_text(
363.0,
164.0,
anchor="nw",
text="VarianteID",
fill="#FFFFFF",
font=("Inter ExtraLightItalic", 15 * -1)
)

canvas.create_text(
461.0,
164.0,
anchor="nw",
text="ProductoID",
fill="#FFFFFF",
font=("Inter ExtraLightItalic", 15 * -1)
)

canvas.create_text(
570.0,
164.0,
anchor="nw",
text="TallaID",
fill="#FFFFFF",
font=("Inter ExtraLightItalic", 15 * -1)
)

canvas.create_text(
647.0,
164.0,
anchor="nw",
text="ColorID",
fill="#FFFFFF",
font=("Inter ExtraLightItalic", 15 * -1)
)

canvas.create_text(
742.0,
164.0,
anchor="nw",
text="SKU",
fill="#FFFFFF",
font=("Inter ExtraLightItalic", 15 * -1)
)

button_image_1 = PhotoImage(
file=relative_to_assets("button_1.png"))
button_1 = Button(
image=button_image_1,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_1 clicked"),
relief="flat"
)
button_1.place(
x=353.0,
y=87.0,
width=185.0,
height=36.0
)

button_image_2 = PhotoImage(
file=relative_to_assets("button_2.png"))
button_2 = Button(
image=button_image_2,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_2 clicked"),
relief="flat"
)
button_2.place(
x=380.0,
y=542.0,
width=113.0,
height=50.0
)

button_image_3 = PhotoImage(
file=relative_to_assets("button_3.png"))
button_3 = Button(
image=button_image_3,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_3 clicked"),
relief="flat"
)
button_3.place(
x=536.0,
y=543.0,
width=118.0,
height=50.0
)

button_image_4 = PhotoImage(
file=relative_to_assets("button_4.png"))
button_4 = Button(
image=button_image_4,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_4 clicked"),
relief="flat"
)
button_4.place(
x=704.0,
y=543.0,
width=118.0,
height=50.0
)

canvas.create_rectangle(
0.0,
0.0,
248.0,
729.0,
fill="#008282",
outline="")

image_image_1 = PhotoImage(
file=relative_to_assets("image_1.png"))
image_1 = canvas.create_image(
115.0,
89.0,
image=image_image_1
)

button_image_5 = PhotoImage(
file=relative_to_assets("button_5.png"))
button_5 = Button(
image=button_image_5,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_5 clicked"),
relief="flat"
)
button_5.place(
x=25.0,
y=480.0,
width=198.0,
height=45.0
)

button_image_6 = PhotoImage(
file=relative_to_assets("button_6.png"))
button_6 = Button(
image=button_image_6,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_6 clicked"),
relief="flat"
)
button_6.place(
x=25.0,
y=171.0,
width=198.0,
height=51.0
)

button_image_7 = PhotoImage(
file=relative_to_assets("button_7.png"))
button_7 = Button(
image=button_image_7,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_7 clicked"),
relief="flat"
)
button_7.place(
x=25.0,
y=253.0,
width=198.0,
height=44.0
)

button_image_8 = PhotoImage(
file=relative_to_assets("button_8.png"))
button_8 = Button(
image=button_image_8,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_8 clicked"),
relief="flat"
)
button_8.place(
x=25.0,
y=328.0,
width=198.0,
height=45.0
)

button_image_9 = PhotoImage(
file=relative_to_assets("button_9.png"))
button_9 = Button(
image=button_image_9,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_9 clicked"),
relief="flat"
)
button_9.place(
x=25.0,
y=404.0,
width=198.0,
height=45.0
)

button_image_10 = PhotoImage(
file=relative_to_assets("button_10.png"))
button_10 = Button(
image=button_image_10,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_10 clicked"),
relief="flat"
)
button_10.place(
x=25.0,
y=556.0,
width=198.0,
height=45.0
)

button_image_11 = PhotoImage(
file=relative_to_assets("button_11.png"))
button_11 = Button(
image=button_image_11,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_11 clicked"),
relief="flat"
)
button_11.place(
x=25.0,
y=632.0,
width=198.0,
height=45.0
)




window.resizable(False, False)
window.mainloop()

I need to import this generate_GUI function that’s why I coded it, any suggestions to solve this behavior?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật