【问题标题】:how to hide top level window icon from the task bar without hiding its border如何从任务栏中隐藏顶级窗口图标而不隐藏其边框
【发布时间】:2019-09-09 06:30:49
【问题描述】:

我正在制作 tkinter 窗口和另一个作为顶层的窗口,但我希望当顶层窗口仅在任务栏中显示一个图标时,它是主窗口图标而不是顶层图标

我已经使用了 overrideredirect(1),它可以工作,但它也隐藏了包括标题栏在内的顶级边框

w = tk.Tk()
w.title('main')
w.geometry('300x300')

def c():
    t = tk.Toplevel()
    t.title('toplevel') 
    t.geometry('100x100')
    # t.overrideredirect(1) 
    t.mainloop()
b = tk.Button(w,text='click',command=c)
b.pack()
w.mainloop()

【问题讨论】:

  • 嗨!亚当。请向我们展示代码或只是特定部分,我们可以从中了解您真正想要实现的目标。
  • 我在 Mac 上,所以我不能这样做,因为它有显示图标的方式,虽然你可以做一件事尝试在顶层窗口上放置一个空白(透明)图标 LINK = @987654321 @。或者尝试在将其设置为 false 之后执行 overrideredirect(0) 和 overrideredirect(1)。我不会保证。

标签: python tkinter


【解决方案1】:

.transient() 方法完全符合您的要求,它将从任务栏中删除顶级图标:

import tkinter as tk
w = tk.Tk()
w.title('main')
w.geometry('300x300')

def c():
    t = tk.Toplevel()
    t.title('toplevel') 
    t.geometry('100x100')
    t.transient(w) 

b = tk.Button(w, text='click', command=c)
b.pack()
w.mainloop()

对了,你只需要调用一次mainloop(),在函数c再调用一次也没用。

【讨论】:

  • 这正是我找了很久的东西!这个答案应该引起更多关注!
猜你喜欢
  • 2015-12-18
  • 1970-01-01
  • 2017-05-28
  • 2012-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多