Reputation: 55
I would like to add a custom minimize button in ### but don't really know how to.
I have tried looking for a bit but only found Python 2 results which no longer work for Python 3.
It would be best if it was possible for both linux and windows (with an os check at the start which I can do myself) and without the use of imported modules off the basic python modules.
Here is my current code:
from tkinter import *
import ctypes
root = Tk()
usr32 = ctypes.windll.user32
res1 = usr32.GetSystemMetrics(0)
res2 = usr32.GetSystemMetrics(1)
#-------------------------------
def ext():
exit()
def minim():
###
root.resizable(0, 0)
root.geometry(str(int(res1 * 0.15)) + "x" + str(int(res2 * 0.1)))
root.overrideredirect(1)
back = Frame(root, bg='black')
back.pack_propagate(0)
back.pack(fill=BOTH, expand=1)
b_Frame = Frame(back, bg="#505050")
b_Frame.place(x=0, y=0, anchor="nw", width=res1 * 0.15, height=res2 * 0.025)
Ext_but = Button(b_Frame, text="X", bg="#FF6666", fg="white", command=ext)
Ext_but.place(x=res1 - res1 * 0.8665, y=0, anchor="nw", width=res1 * 0.016, height=res2 * 0.025)
Min_but = Button(b_Frame, text="_", bg="#FF6666", fg="white", command=minim)
Min_but.place(x=res1 - res1 * 0.8825, y=0, anchor="nw", width=res1 * 0.016, height=res2 * 0.025)
#-------------------------------
root.mainloop()
Upvotes: 0
Views: 2266
Reputation: 451
You can use:
root.wm_state("iconic")
For example a button that does this could be:
tk.Button(root, text = "Mimimize", command = lambda: root.wm_state("iconic")).pack()
So in your example it would be:
def minim():
root.wm_state("iconic")
Uses standard modules (as requested). Tested in Windows 10 in Python 3.6, but it should work with all operating systems and Python versions.
Upvotes: 1