0

I want to create a custom Title-bar. But I have a problem with the icon. I want it to be left but instead it is just in the window... enter image description here

I have my template from here: https://github.com/Terranova-Python/Tkinter-Menu-Bar/blob/main/main.py

The code I tried to add the image:

from PIL import Image, ImageTk

img  = Image.open("M.ico") 
photo=ImageTk.PhotoImage(img)

close_button = Button(title_bar, text='  ×  ', command=root.destroy,bg=RGRAY,padx=2,pady=2,font=("calibri", 13),bd=0,fg='white',highlightthickness=0)
expand_button = Button(title_bar, text='  ', command=maximize_me,bg=RGRAY,padx=2,pady=2,bd=0,fg='white',font=("calibri", 13),highlightthickness=0)
minimize_button = Button(title_bar, text='  ',command=minimize_me,bg=RGRAY,padx=2,pady=2,bd=0,fg='white',font=("calibri", 13),highlightthickness=0)
title_bar_image = Label(image=photo,bg=RGRAY,padx=2,pady=2,bd=0)
title_bar_title = Label(title_bar, text=tk_title, bg=RGRAY,bd=0,fg='white',font=("helvetica", 10),highlightthickness=0)

I hope somebody can help me :)

Muddyblack k
  • 314
  • 3
  • 16
  • I don't fully understand what you are asking, you want to set the window icon, right? – coulomb Nov 05 '21 at 21:34
  • Well normally it does look like this: [https://i.imgur.com/WfBmgDe.png](https://i.imgur.com/WfBmgDe.png) But I override the titlebar so I can create my own but I dont know how to get the image left to the title "App" – Muddyblack k Nov 05 '21 at 21:43
  • 2
    Is it because you need to parent (anchor) the image to title_bar? – coulomb Nov 05 '21 at 21:53
  • Ups yes thank you xD title_bar_image = Label(title_bar, image=photo, width=25, height=25, bg=RGRAY, bd=0) fixed it – Muddyblack k Nov 05 '21 at 22:02

1 Answers1

1

To have an official answer, the problem was that title_bar_image was not anchored to title_bar. The revised code snippet is now

from PIL import Image, ImageTk

img  = Image.open("M.ico") 
photo=ImageTk.PhotoImage(img)

close_button = Button(title_bar, text='  ×  ', command=root.destroy,bg=RGRAY,padx=2,pady=2,font=("calibri", 13),bd=0,fg='white',highlightthickness=0)
expand_button = Button(title_bar, text='  ', command=maximize_me,bg=RGRAY,padx=2,pady=2,bd=0,fg='white',font=("calibri", 13),highlightthickness=0)
minimize_button = Button(title_bar, text='  ',command=minimize_me,bg=RGRAY,padx=2,pady=2,bd=0,fg='white',font=("calibri", 13),highlightthickness=0)
title_bar_image = Label(title_bar, image=photo,bg=RGRAY,padx=2,pady=2,bd=0)
title_bar_title = Label(title_bar, text=tk_title, bg=RGRAY,bd=0,fg='white',font=("helvetica", 10),highlightthickness=0)
coulomb
  • 698
  • 6
  • 16