0

This is my 2nd question on python/tkinter... I'm experimenting on containers to maximise code reuse but I seem to be stuck at attempting to display the image for the ContainerImage section although at runtime it does set the background to black and displays the text just not the image. Would appreciate any pointers on fixing this. Thanks

import tkinter as tk
import time


class Application(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.withdraw()  # Hide the root while it is built.
        self.title("DoA Tools")
        self.resizable(width=False, height=False)
        win_width = 800
        win_height = 450
        scr_width = (self.winfo_screenwidth() - win_width) // 2
        scr_height = (self.winfo_screenheight() - win_height) // 2
        self.geometry("{0}x{1}+{2}+{3}".format(win_width, win_height, scr_width, scr_height))
        self.call('wm', 'iconphoto', self._w, tk.PhotoImage(file="icon.png"))
        # Temporary Placeholders
        ContainerMain(self, "Title Text", "Content Text")
        ContainerButton(self)
        ContainerImage(self)


class ContainerMain(tk.Frame):
    def __init__(self, parent, header="", subheader=""):
        tk.Frame.__init__(self, parent)
        self.place(x=200, y=0, height=400, width=600)
        self.configure(bg="white")
        # Temporary Placeholders
        hdr_title = tk.Label(self, text=header)
        hdr_title.place(x=10, y=15, height=21, width=575)
        hdr_title.configure(bg="white", width=600, anchor="w", font="TkDefaultFont 9 bold")
        hdr_subtitle = tk.Label(self, text=subheader)
        hdr_subtitle.place(x=10, y=44, height=21, width=575)
        hdr_subtitle.configure(bg="white", width=600, anchor="nw")


class ContainerButton(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        self.place(x=-2, y=400, height=54, width=804)
        self.configure(borderwidth="2", relief="groove", width=804)
        # Temporary Placeholders
        btn_close = tk.Button(self, text="Exit")
        btn_close.place(x=710, y=10, height=30, width=80)


class ContainerImage(tk.Label):
    def __init__(self, parent):
        tk.Label.__init__(self, parent)
        self.place(x=0, y=0, height=400, width=200)
        # temporary Placeholders
        image = tk.PhotoImage(master=self, file="side.png")
        self.configure(text="Side Image", fg='white', bg='black', bd=0, image=image, compound="center")


class AccountManagement:
    def __init__(self, root):
        self.__root = root
        self.__root.deiconify()
2
Contributors
1
Reply
22
Views
11 Months
Discussion Span
Last Post by Gribouillis
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.