Python Forum
[Tkinter] Hi, Keep postition of main window after iconify()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Hi, Keep postition of main window after iconify()
#2
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."
Reply


Messages In This Thread
RE: Hi, Keep postition of main window after iconify() - by DT2000 - Jul-11-2020, 07:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 598 Mar-17-2024, 09:37 AM
Last Post: deanhystad
Exclamation [Tkinter] Error when closing the main window with destroy TomasSanchexx 1 817 Aug-06-2023, 01:54 AM
Last Post: deanhystad
  [PyQt] Can't get MDIarea to resize automatically with Main Window JayCee 4 3,515 Aug-02-2021, 08:47 PM
Last Post: JayCee
  [PyQt] How to clip layout to sides and bottom of main window? Valmont 9 5,004 Mar-24-2021, 10:00 PM
Last Post: deanhystad
  "tkinter.TclError: NULL main window" Rama02 1 5,906 Feb-04-2021, 06:45 PM
Last Post: deanhystad
  [Tkinter] Auto re-fit frames sizes in main window Gilush 2 2,687 Jun-06-2020, 03:14 AM
Last Post: Gilush
  [Tkinter] How to add multiple frames to main window Dandy_Don 13 8,104 Apr-29-2020, 09:21 PM
Last Post: Dandy_Don
  tkinter window and turtle window error 1885 3 6,779 Nov-02-2019, 12:18 PM
Last Post: 1885
  “main thread is not in main loop” in Tkinter Long_r 1 24,367 Jun-26-2019, 11:00 PM
Last Post: metulburr
  pyqt main window refresh poblems duende 0 5,398 Apr-13-2018, 05:05 PM
Last Post: duende

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020