Tkinter, Windows: How do I view a window in the Windows taskbar that has no title?
1 answer
Tk does not provide a way to have a top-level window that displays a set of overridden links in the taskbar. To do this, the window must have the WS_EX_APPWINDOW extended style applied , and in this Tk window type, WS_EX_TOOLWINDOW is set instead. We can use the python ctypes extension to reset, but we need to note that Tk toplevel windows on Windows are not directly controlled by the window manager. Therefore, we must apply this new style to the parent of the windows returned by the method winfo_id
.
The following example shows such a window.
import tkinter as tk
import tkinter.ttk as ttk
from ctypes import windll
GWL_EXSTYLE=-20
WS_EX_APPWINDOW=0x00040000
WS_EX_TOOLWINDOW=0x00000080
def set_appwindow(root):
hwnd = windll.user32.GetParent(root.winfo_id())
style = windll.user32.GetWindowLongPtrW(hwnd, GWL_EXSTYLE)
style = style & ~WS_EX_TOOLWINDOW
style = style | WS_EX_APPWINDOW
res = windll.user32.SetWindowLongPtrW(hwnd, GWL_EXSTYLE, style)
# re-assert the new window style
root.wm_withdraw()
root.after(10, lambda: root.wm_deiconify())
def main():
root = tk.Tk()
root.wm_title("AppWindow Test")
button = ttk.Button(root, text='Exit', command=lambda: root.destroy())
button.place(x=10,y=10)
root.overrideredirect(True)
root.after(10, lambda: set_appwindow(root))
root.mainloop()
if __name__ == '__main__':
main()
+4
source to share