Is it possible to display the icon for my toplevel
and root
window after removing the minimize and maximize buttons? I tried using -toolwindow
but the icon can't be displayed afterwards. Is there another way I can remove the min and max size buttons from window while still displaying the icon?
from tkinter import *
def top():
tp = Toplevel()
tp.geometry("300x300")
tp.attributes("-toolwindow", 1)
tp.iconbitmap("My icon.ico")
root = Tk()
root.geometry("400x400")
b = Button(root, text="open window with icon", command=top).pack()
root.mainloop()
Windows-specific solution
First option is to make your
toplevel
window transient for theroot
window which is a really simple solution.All you need to do is change line
tp.attributes("-toolwindow", 1)
totp.transient(root)
!Second option is more complicated, but more universal within the Windows system.
Each window in the Windows system has it's own style, which is represented as a logical disjunction of bit-styles. You can build the new style from a scratch or set new style to disjunction of the old one with a bit-style (to switch it on) or to conjunction of the old one with a negation of bit-style (to switch it off):
new style = old style AND NOT Maximize AND NOT Minimize
new style = old style OR Maximize OR Minimize
For all that interaction we need the ctypes library (comes with python) and a set of the WinAPI functions:
Check this example: