Jul-11-2020, 07:56 PM
You can setup the configuration for your window size and monitor display this way. When you iconify the window it will again appear in the same position as it was initially displayed, centered in the frame when you click the tray icon to bring it back into view.
from tkinter import * import pywintypes import win32con import win32api root = Tk() devmode = pywintypes.DEVMODEType() #set you window display configuration to what you want it below devmode.PelsWidth = 1280 devmode.PelsHeight = 1024 devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT win32api.ChangeDisplaySettings(devmode, 0) # set your window size below w = 500 h = 500 ws = root.winfo_screenwidth() hs = root.winfo_screenheight() x = (ws/2) - (w/2) y = (hs/2) - (h/2) root.geometry('%dx%d+%d+%d' % (w, h, x, y)) root.resizable(height=FALSE,width=FALSE) def resize(): root.iconify() minimize = Button(root,text="Minimize", command = resize) minimize.pack() root.mainloop() win32api.ChangeDisplaySettings(None, 0)
"Often stumped... But never defeated."