Report this

What is the reason for this report?

How can I combine, organize, and solve the Python tkinter with Parent, child, and application classes?

Posted on October 12, 2024

Dear Community! No matter how I try to write the code, one image always appears twice! What’s wrong?

import tkinter as tk
from tkinter import ttk


class Szulo(ttk.Frame):
    def __init__(self, container):
        super().__init__(container)

        self.kep1 = tk.PhotoImage(file='../globalkep/z11.png')
        ttk.Button(self, image=self.kep1).pack(padx=5, pady=5)


class Gyerek(Szulo):
    def __init__(self, container):
        super().__init__(container)

        self.kep2 = tk.PhotoImage(file='../globalkep/p11.png')
        ttk.Button(self, image=self.kep2).pack(padx=5, pady=5)


class App(tk.Tk):
    def __init__(self):
        super().__init__()
        self.geometry('600x500+500+50')
        self.configure(bg='green')

        szulo = Szulo(self)
        szulo.pack(padx=20, pady=20)

        gyerek = Gyerek(self)
        gyerek.pack(padx=20, pady=20)


if __name__ == '__main__':
    app = App()
    app.mainloop()

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.