[Python] Tkinter centering label

Discussão em 'Python' iniciado por Stack, Março 2, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to place a label in the middle of my frame to display random files but its not showing up? Here is my code

    def tok_setup(self):

    left = Image.open("left.png")
    right = Image.open("right.png")


    leftsize = left.resize((50,50), Image.LANCZOS)
    rightsize = right.resize((50,50), Image.LANCZOS)

    self.trashImage = ImageTk.PhotoImage(leftsize)
    self.keepImage = ImageTk.PhotoImage(rightsize)

    Label(self.trash_or_keep_frame, text="Trash or Keep", bg="#8d5159").pack(side=TOP, pady=10, anchor="n")
    Button(self.trash_or_keep_frame, text="Main", command=self.goto_main, bg="#8d5159").pack(side=BOTTOM, pady=10)

    randomfile = Label(self.trash_or_keep_frame, text="file", relief="sunken")
    randomfile.place(relx=0.5, rely=0.5, anchor=CENTER)

    Button(self.trash_or_keep_frame, image = self.trashImage, text="left", borderwidth=0).pack(side=LEFT)
    Button(self.trash_or_keep_frame,image = self.keepImage, text="right", borderwidth=0).pack(side=RIGHT)
    self.add_image(self.trash_or_keep_frame,'cat.jpg')

    canvas = Canvas(self.trash_or_keep_frame, bg="pink", width=100, height=100)
    canvas.pack(expand=True, fill=BOTH)


    My canvas isn't showing up either, i have been looking up solutions but nothing has helped.

    Continue reading...

Compartilhe esta Página