nicochulo
nicochulo

Reputation: 111

Make a GUI that doesn't show in taskbar

I am trying to display a tkinter window (with an image,in my case) that doesn't show on the taskbar. I've already tried using the method described here, but the person that answered didn't provide an example so I am unable to replicate it (and I'm using Windows 10 so maybe that is another factor to consider).

My code is here. I am using Python 3.5

from tkinter import Toplevel, Tk, Label, PhotoImage

win = Tk()

win.attributes('-alpha', 0.0)
win.iconify()

window = Toplevel(win)
window.geometry("500x500+100+100")
window.overrideredirect(1)

photo = PhotoImage(file="testfile.png")

label = Label(window, image=photo)
label.pack()

win.mainloop()

Upvotes: 1

Views: 561

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 148890

The linked question contained an interesting comment recommending to reverse what was done in that other answer. Along with this accepted answer that explains that what is needed is just to set the WS_EX_TOOLWINDOW style, a simple example is:

import tkinter as tk
import tkinter.ttk as ttk
from ctypes import windll

GWL_EXSTYLE=-20
WS_EX_TOOLWINDOW=0x00000080

def set_toolwindow(root):
    hwnd = windll.user32.GetParent(root.winfo_id())
    style = windll.user32.GetWindowLongPtrW(hwnd, GWL_EXSTYLE)
    style = style | WS_EX_TOOLWINDOW
    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_toolwindow(root))
    root.mainloop()

if __name__ == '__main__':
    main()

Upvotes: 2

Related Questions