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?