Python Forum
Images in tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Images in tkinter
#1
I've been posing on here about my learning project as some of you have read.
Currently I'm working on learning more on classes and methods.
While re-writing my script something unexpected happened.
The original code will show the header image but, the re-written code will not.
I can put text on the label and it will work. I can put color on the container frame and widget.
I can even use tk.Label and the size of the container will be there.(See image below)
For the life of me, I can't seem to get the image to show.
[Image: book.png]

Relevant code
import tkinter as tk
from tkinter import ttk

class RootWindow:
    '''RootWindow'''
    def __init__(self, master):
        self.master = master
        self.master.grid_columnconfigure(0, weight=1)
        self.master.rowconfigure(0, weight=1)
        self.logo_frame()

        Child(self.logoframe)
        
        def logo_frame(self):
        '''logo frame'''
        style= ttk.Style()
        style.configure('TY.TFrame', background='orange')
        self.logoframe = ttk.Frame(self.master, border=5, relief='ridge', style='TY.TFrame')
        self.logoframe.grid(column=0, row=0, sticky='new')
        self.logoframe.grid_columnconfigure(0, weight=3)


class Child:
    '''Child'''
    def __init__(self, logoframe):
        self.my_logo(logoframe)

    def my_logo(self, logoframe):
        '''logo'''
        self.imgfile = tk.PhotoImage(file='/home/johnny/Desktop/CookBook/images/cookbook_logo.png')
        img_logo = tk.Label(logoframe, image=self.imgfile, anchor='n', bg='pink')
        img_logo.grid(column=0, row=0, sticky='new')

def main():
    '''main'''
    root = tk.Tk()
    root.resizable(width=False, height=False)
    RootWindow(root)
    root.mainloop()

if __name__ == '__main__':
    main()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Images in tkinter - by menator01 - Apr-25-2020, 12:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems trying to position images with Tkinter emont 3 805 Dec-12-2023, 07:20 AM
Last Post: menator01
  [Tkinter] Loading Images to Tkinter with Pillow Tomli 2 13,053 Jun-18-2020, 03:26 AM
Last Post: Tomli
  tkInter and Pillow don't display any images in GUIs - program gives errors instead SomeRandomGuy 9 10,878 Oct-29-2019, 02:57 PM
Last Post: SomeRandomGuy
  [Tkinter] Help with tkinter; images and button commands SheeppOSU 2 3,009 Mar-28-2019, 02:01 AM
Last Post: woooee
  Remove duplicate images - tkinter? darter 5 5,379 Nov-10-2018, 10:54 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020