python - 制作一个不显示在任务栏中的 GUI

标签 python tkinter

我正在尝试显示一个未显示在任务栏上的 tkinter 窗口(在我的例子中带有图像)。我已经尝试使用描述的方法 here ,但回答者没有提供示例,因此我无法复制它(而且我使用的是 Windows 10,所以也许这是另一个需要考虑的因素)。

我的代码在这里。我正在使用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()

最佳答案

链接的问题包含一条有趣的评论,建议扭转 that other answer 中所做的事情。除此之外accepted answer这说明只需要设置 WS_EX_TOOLWINDOW 样式即可,一个简单的例子是:

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()

关于python - 制作一个不显示在任务栏中的 GUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48815731/

相关文章:

python - 跨 NAT 的 UDP 客户端无法从服务器接收数据

python - 高效计算过滤列表的大小

python - 语法警告 : name 'color' is assigned to before global declaration global color Python

python - Matlab 到 Python : Solving the system using SVD

python - python sql查询中的while循环

python - 如何在枕头中使用 alpha_composite?

python - 简单的 Tk 应用程序——单击按钮进行绘制

python - 将变量传递给框架

python - 跟踪变量 - ComboBox Tkinter

python - 使用 filedialog 时 Tkinter 窗口和脚本卡住