0

enter image description here

My GUI looks like this. I don't know why. It looks fine without assigning the frame to a class. But the moment I assign it to one, boom, there is an entry box at the top middle that I didn't ask for, another entry box atop the button, and these are the areas where there should be images appearing, not entry boxes.

This is how I want it to look like: enter image description here

(Yes, the Write down prompt and NEXT are images, not text. I did this so I can write text without using fonts, which is a nightmare as users have to manually install them.) Here's the code I used, I could remove more from the code but it'd defeat the purpose of finding out why these elements don't appear:

from pathlib import Path
from tkinter import Tk, Canvas, Entry, Text, Button, PhotoImage, Frame


OUTPUT_PATH = Path(__file__).parent
ASSETS_PATH = OUTPUT_PATH / Path("./assets")


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

class FirstFrame(Frame):
    def __init__(self, parent, **kwargs):
        super().__init__(parent, **kwargs)
        
        parent = Tk()

        parent.geometry("851x605")
        parent.configure(bg = "#FFFFFF")

        canvas = Canvas(
            self,
            bg = "#FFFFFF",
            height = 605,
            width = 851,
            bd = 0,
            highlightthickness = 0,
            relief = "ridge"
        )

        canvas.place(x = 0, y = 0)
        canvas.create_rectangle(
            0.0,
            0.0,
            851.0,
            605.0,
            fill="#2E3440",
            outline="")

        self.entry_image_1 = PhotoImage(
            file=relative_to_assets("entry_1.png"))
        entry_bg_1 = canvas.create_image(
            442.3427429199219,
            228.64744186401367,
            image=self.entry_image_1
        )
        entry_1 = Text(
            self,
            bd=0,
            bg="#E5E9F0",
            highlightthickness=0
        )
        entry_1.place(
            x=150.69793701171875,
            y=184.33592224121094,
            width=583.2896118164062,
            height=86.62303924560547
        )

        self.entry_image_2 = PhotoImage(
            file=relative_to_assets("entry_2.png"))
        entry_bg_2 = canvas.create_image(
            425.2044982910156,
            361.8774185180664,
            image=self.entry_image_2
        )
        entry_2 = Entry(
            bd=0,
            bg="#D8DEE9",
            highlightthickness=0
        )
        entry_2.place(
            x=50.823601722717285,
            y=323.1786880493164,
            width=748.7617931365967,
            height=75.3974609375
        )

        self.button_image_1 = PhotoImage(
            file=relative_to_assets("button_1.png"))
        button_1 = Button(
            image=self.button_image_1,
            borderwidth=0,
            highlightthickness=0,
            command=lambda: print("button_1 clicked"),
            relief="flat"
        )
        button_1.place(
            x=316.1701354980469,
            y=436.61621856689453,
            width=218.65972900390625,
            height=77.3974609375
        )

        self.entry_image_3 = PhotoImage(
            file=relative_to_assets("entry_3.png"))
        entry_bg_3 = canvas.create_image(
            425.20452880859375,
            475.31494903564453,
            image=self.entry_image_3
        )
        entry_3 = Text(
            bd=0,
            bg="#FFFFFF",
            highlightthickness=0
        )
        entry_3.place(
            x=385.9048767089844,
            y=453.15918731689453,
            width=78.59930419921875,
            height=42.3115234375
        )
def main():
    root = Tk()
    root.geometry("851x605")
    root.configure()
    first_frame = FirstFrame(root)
    first_frame.pack(fill="both", expand=True)
    root.mainloop()

main()
  • What exactly does "assigning the frame to a class" mean? Regardless, see [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged) – martineau Feb 09 '22 at 19:59
  • It's also unclear why users would have to install fonts in order for your program to write text. – martineau Feb 09 '22 at 20:03
  • You're explicitly creating multiple text and entry widgets. Which widget is the extra entry? – Bryan Oakley Feb 09 '22 at 20:46
  • 1
    There are two instances of `Tk()`. Why do you create another instance of `Tk()` inside `FirstFrame`? – acw1668 Feb 10 '22 at 00:35

0 Answers0