2

i am making tkinter window and another one as top level but i want when the top level window is displayed only one icon in the task bar which is main window icon not the top level one

I already used overrideredirect(1), it works but it also hid top level border including title bar

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()
adham khaled
  • 37
  • 2
  • 6
  • Hi! Adam. Please show us the code or just the specific part from which we can understand what you really trying to achieve. – Saad Apr 18 '19 at 22:04
  • I'm on Mac so I can't this as it has way of displaying icon though you can do one thing try putting a blank(transparent) icon on your top-level window LINK = https://stackoverflow.com/questions/550050/removing-the-tk-icon-on-a-tkinter-window. Or try doing `overrideredirect(0)` and `overrideredirect(1)` just after you set it false. I will not guarantee. – Saad Apr 19 '19 at 05:13
  • Relevant [making-tkinter-multiple-windows-have-one-icon-in-the-task-bar](https://stackoverflow.com/questions/50760753/making-tkinter-multiple-windows-have-one-icon-in-the-task-bar) – stovfl Apr 19 '19 at 08:52

1 Answers1

1

The method .transient() does exactly what you want, it will remove the toplevel icon from the taskbar:

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

By the way, you only need to call mainloop() once, calling it again in the function c is useless.

j_4321
  • 15,431
  • 3
  • 34
  • 61