Python Forum
Icon in tkinter - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Icon in tkinter (/thread-26346.html)



Icon in tkinter - menator01 - Apr-29-2020

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]


RE: Icon in tkinter - DT2000 - Apr-29-2020

In order for people to offer help, you need to post your code.


RE: Icon in tkinter - menator01 - Apr-29-2020

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()



RE: Icon in tkinter - DT2000 - Apr-29-2020

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()



RE: Icon in tkinter - menator01 - Apr-29-2020

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.


RE: Icon in tkinter - wuf - Apr-29-2020

Hi menator01

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

wuf :-)


RE: Icon in tkinter - menator01 - Apr-29-2020

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)



RE: Icon in tkinter - menator01 - Apr-30-2020

It's the os. Tried on my windows os and the icon is in the right place.
[Image: Capture.PNG]


RE: Icon in tkinter - wuf - May-03-2020

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 :-)