Can’t change the icon on my 2nd window who make the principal window on the taskbar cause a custom title bar.
I have make a program with a custom title bar that’s work good, i have a icon in my task bar when i minimize him but the icon is the tkinter default and a iconbitmap or iconphoto can’t change icon.
from tkinter import *
#? Function
def quit_app():
root.destroy()
event_handler.destroy()
def minimize_click():
root.update_idletasks()
root.overrideredirect(False)
root.state('iconic')
event_handler.withdraw()
def on_icon_click_return_window(event):
root.update_idletasks()
root.overrideredirect(True)
root.state('normal')
event_handler.deiconify()
def adjust_frame_size():
root.update_idletasks()
width = cross.width()
height = cross.height()
title_bar.config(width=width, height=height)
def on_drag_start(event):
global drag_start_x, drag_start_y
drag_start_x, drag_start_y = event.x, event.y
def on_drag_motion(event):
x, y = root.winfo_pointerx() - drag_start_x, root.winfo_pointery() - drag_start_y
root.geometry(f'+{x}+{y}')
#? Variable
root = Tk()
root.geometry("800x600")
root.config(bg="#242727")
root.overrideredirect(True)
event_handler = Tk()
event_handler.attributes("-alpha", 0.0)
event_handler.lift()
title_bar = Frame(root, bg='#1e1e1e')
title_bar.pack(fill=X)
cross = PhotoImage(file="res/cross.png")
moins = PhotoImage(file="res/moin.png")
close_button = Button(title_bar, image=cross, bg="#1e1e1e", command=quit_app, relief='sunken', borderwidth=0)
close_button.pack(side=RIGHT)
minimize_button = Button(image=moins, command=minimize_click, bg="#1e1e1e", relief='sunken', borderwidth=0)
minimize_button.bind("<Map>", on_icon_click_return_window)
minimize_button.place(x=748, y=5.5)
#! Demarage
root.after(100, adjust_frame_size)
#! Mouvement de fenetre
drag_start_x = drag_start_y = 0
title_bar.bind("<Button-1>", on_drag_start)
title_bar.bind("<B1-Motion>", on_drag_motion)
root.mainloop()
Sorry for my english 😉
Ty
New contributor
nev626 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.