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]
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#2
In order for people to offer help, you need to post your code.
"Often stumped... But never defeated."
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()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


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()
"Often stumped... But never defeated."
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.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


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)
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#8
It's the os. Tried on my windows os and the icon is in the right place.
[Image: Capture.PNG]
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


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
Exclamation [PyQt] Setting icon on QAction from outside QGuiApplication gradlon93 3 1,677 Jan-04-2023, 11:37 AM
Last Post: gradlon93
  PyQt6 QAction with icon and string malonn 2 1,617 Sep-12-2022, 11:59 AM
Last Post: malonn
  how to remove icon ilyess68ysl 4 3,581 Oct-15-2021, 10:05 AM
Last Post: ilyess68ysl
  [Tkinter] Password Reveal Icon Evil_Patrick 2 4,586 Nov-29-2019, 02:20 PM
Last Post: Evil_Patrick
  [Tkinter] Window Icon Evil_Patrick 6 7,978 Oct-18-2019, 11:26 AM
Last Post: Evil_Patrick
  Button with Image Icon Friend 2 6,766 Jul-25-2019, 09:39 AM
Last Post: Friend
  [PyQt] Hide Dock Icon for QSystemTrayIcon App AeglosGreeenleaf 0 3,264 Jun-20-2019, 07:21 PM
Last Post: AeglosGreeenleaf
  [PyQt] How is this tray icon throbber done? JackDinn 7 4,735 Mar-05-2018, 02:19 PM
Last Post: JackDinn
  tkinter filedialog and pickle - custom icon question. kim07133 0 2,723 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