Python Forum

Full Version: Icon in tkinter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have been researching a little on putting icons in the top level window on my script.
I can get it to work but, it's not in the window where the root title is. It's in the upper left corner of the desktop.
Think maybe because on linux the desktop itself is a window?
Of coarse they were examples on windows pc too.
As you can see the icon in the left top corner. The examples I seen on the net show it by the title bar on the root window.
Any thoughts?

[Image: screen.png]
In order for people to offer help, you need to post your code.
The code is one line.
The relevant block
def main():
    '''Docstring'''
    root = tk.Tk()
    root.title('Johnny\'s CookBook')
    img = tk.PhotoImage(file='/home/johnny/Desktop/CookBook/images/cookbook_logo.png')
    root.configure(width=img.width())
    root.resizable(width=False, height=False)
    root.iconphoto(True, tk.PhotoImage(file='images/ratt2b.png'))
    RootWindow(root)
    root.mainloop()

if __name__ == '__main__':
    main()
Give this a try, I do not run Linux so I cannot test on that system.
def main():
    '''Docstring'''
    root = tk.Tk()
    root.title('Johnny\'s CookBook')
    img = tk.PhotoImage(file='/home/johnny/Desktop/CookBook/images/cookbook_logo.png')
    root.configure(width=img.width())
    root.resizable(width=False, height=False)
    photo = PhotoImage(file = 'images/ratt2b.png')
    root.iconphoto(False, photo)
    RootWindow(root)
    root.mainloop()
Looks like you just took my one line and broke it into two line. The True False is for either display on all top windows or just current. Or atleast that's what I got from the articles I read.
Hi menator01

Where does the object RootWindow come from? I can't see its creation in your code snippet.

wuf :-)
Here is the top part of the code

###### Intiate the window ######
class RootWindow:
    '''Docstring'''
    def __init__(self, master):
        self.master = master
        self.master.columnconfigure(0, weight=1)
        self.master.rowconfigure(0, weight=1)

        ###### Intiate all of our main containerframes ######
        self.logo_frame()
        self.letter_frame()
        self.container_frame()
        self.title_frame()
        self.recipe_frame()
        self.footer_frame()

        ###### Initate the widgets ######
        Child(self.logoframe, self.footerframe)
        Child2().lettermenu(self.letterframe, self.titleframe, self.recipeframe)
        Child3().titlemenu(self.titleframe, self.recipeframe)
        Child4().recipe(self.recipeframe)
It's the os. Tried on my windows os and the icon is in the right place.
[Image: Capture.PNG]
Hi menator01

Sorry for my late answer. You are right for instance by Ubuntu 18.04 the icon of an apllication das not appear on its window title bar but in the Top bar of an desktop in witch the application is running. If the favorit bar is activated the icon of an application does also inlarged appear in it.

All the best from wuf :-)