Tkinter 将图标添加到自定义 title-bar(已覆盖)
Tkinter add icon to custom title-bar (overridden)
我想创建自定义 Title-bar。但是我的图标有问题。
我想保留它,但它只是在 window...
我的模板来自这里:https://github.com/Terranova-Python/Tkinter-Menu-Bar/blob/main/main.py
我尝试添加图片的代码:
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)
我希望有人能帮助我:)
要正式回答,问题是 title_bar_image
没有锚定到 title_bar
。修改后的代码片段现在是
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)
我想创建自定义 Title-bar。但是我的图标有问题。
我想保留它,但它只是在 window...
我的模板来自这里:https://github.com/Terranova-Python/Tkinter-Menu-Bar/blob/main/main.py
我尝试添加图片的代码:
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)
我希望有人能帮助我:)
要正式回答,问题是 title_bar_image
没有锚定到 title_bar
。修改后的代码片段现在是
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)