Muddyblack k
Muddyblack k

Reputation: 252

Tkinter add icon to custom title-bar (overridden)

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

Upvotes: 0

Views: 1194

Answers (1)

coulomb
coulomb

Reputation: 706

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)

Upvotes: 1

Related Questions