pythontkintercustomtkinter

Issue using app.overrideredirect(True) in my CustomTkinter application


I'm using app.overrideredirect(True) in my customtkinter application to create a custom title bar. However, the application doesn't appear in the Windows taskbar. When I click outside the app, it disappears completely and I can't bring it back with Alt+Tab or Windows+Tab

from customtkinter import *


app = CTk()
app.geometry("350x500")
app.title("WHC Launcher | Sign In")
app.overrideredirect(True)
app.iconbitmap("WHC.ico")
app.wm_attributes("-toolwindow", False)


minimize_button = CTkButton(app, text="−", font=("Arial", 20), width=30, height=30, corner_radius=0, fg_color="transparent", hover_color="#333333", command=lambda: app.withdraw())
minimize_button.place(x=270, y=10)

close_button = CTkButton(app, text="✕",  font=("Arial", 18), width=30, height=30, corner_radius=0, fg_color="transparent", hover_color="#FF0000", command=app.destroy)
close_button.place(x=305, y=10)

app.mainloop()

Tried creating a "Dummy Window"(invisible window) which acts as the main application window, as ChatGPT suggested, but still didn't work.

root = CTk() root.withdraw()  # Hide the root window  

It literally didn't change anything


Solution

  • For Windows 10 or 11 platform, you can try the module hPyT to hide the title bar and keep the icon in the taskbar:

    import customtkinter as ctk
    import hPyT
    
    app = ctk.CTk()
    hPyT.title_bar.hide(app)
    ...
    

    Result:

    enter image description here


    PS: Suggest to use app.iconify instead of app.withdraw to minimize the window.