Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Icon in tkinter
#1
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]
Reply
#2
In order for people to offer help, you need to post your code.
Reply
#3
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()
Reply
#4
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()
Reply
#5
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.
Reply
#6
Hi menator01

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

wuf :-)
Reply
#7
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)
Reply
#8
It's the os. Tried on my windows os and the icon is in the right place.
[Image: Capture.PNG]
Reply
#9
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 :-)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Password Reveal Icon Evil_Patrick 2 804 Nov-29-2019, 02:20 PM
Last Post: Evil_Patrick
  [Tkinter] Window Icon Evil_Patrick 6 2,835 Oct-18-2019, 11:26 AM
Last Post: Evil_Patrick
  Button with Image Icon Friend 2 1,430 Jul-25-2019, 09:39 AM
Last Post: Friend
  [PyQt] How is this tray icon throbber done? JackDinn 7 1,792 Mar-05-2018, 02:19 PM
Last Post: JackDinn
  tkinter filedialog and pickle - custom icon question. kim07133 0 1,210 Jan-08-2018, 12:10 PM
Last Post: kim07133

Forum Jump:

User Panel Messages

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