Feature request: Enable detection of window minimised state
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 39/100
Research direction
Start by tracing the window.read and window.minimize entry points, then inspect how window.TKroot.state() and winfo_viewable() are exposed across supported platforms. The issue names no source files or tests; done should provide a reliable way to distinguish minimized, restored, and systray states so applications can respond accordingly.
Written by the indexing model from the issue text.
Description
It would help to have a feature that allows detecting whether the window is minimised or un-minimised or in systray. The reason it helps to have this feature is that the programmer can then write code to avoid having to process any GUI event loop when the program is minimised. In certain programs this can help save a huge amount of processing.
I tried asking an LLM if such a feature is already available, and it generated the below code but it does not detect the minimised and un-minimised state.
import platform
# Identify the OS
OS_TYPE = platform.system() # Returns 'Linux', 'Windows', or 'Darwin' (macOS)
layout = [
[sg.Text("Window State Monitor", font=("Helvetica", 16))],
[sg.Text("Current State:", size=(15, 1)), sg.Text("", key="-STATE-", text_color="yellow")],
[sg.Button("Minimize Me"), sg.Button("Exit")]
]
window = sg.Window("OS State Demo", layout, finalize=True)
while True:
# Use a short timeout to refresh the check periodically
event, values = window.read(timeout=200)
if event in (sg.WIN_CLOSED, 'Exit'):
break
if event == "Minimize Me":
window.minimize()
# --- CROSS-PLATFORM STATE DETECTION ---
# 1. Get the standard tkinter state
raw_state = window.TKroot.state()
# 2. Check if the window is physically 'viewable' (especially useful on Linux)
# returns 1 if visible on screen, 0 if minimized/hidden
is_viewable = window.TKroot.winfo_viewable()
display_status = "Unknown"
if OS_TYPE == "Windows":
# Windows handles 'zoomed' and 'iconic' reliably
if raw_state == "iconic":
display_status = "MINIMIZED"
elif raw_state == "zoomed":
display_status = "MAXIMIZED"
else:
display_status = "VISIBLE (Normal)"
elif OS_TYPE == "Linux":
# On Linux, raw_state often stays 'normal'. Use winfo_viewable for accuracy.
if is_viewable == 0 or raw_state == "iconic":
display_status = "MINIMIZED (Iconified)"
else:
display_status = "VISIBLE (Normal)"
elif OS_TYPE == "Darwin": # macOS
if raw_state == "iconic":
display_status = "MINIMIZED"
else:
display_status = "VISIBLE"
# Update GUI and Console
window["-STATE-"].update(display_status)
print(f"[{OS_TYPE}] Raw State: {raw_state} | Viewable: {is_viewable} | Status: {display_status}")
window.close()
- Dominant language
- Python
- Stars
- 867
- Forks
- 106
- Avg merge
- 1m
- Merged PRs (30d)
- 2
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from spyoungtech/FreeSimpleGUI
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
spyoungtech/FreeSimpleGUI#109 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
spyoungtech/FreeSimpleGUI#86 · 1 comment · 2 reactions ·
-
Difficulty 1/5 Under an hour Newbie friendliness 58/100
spyoungtech/FreeSimpleGUI#101 · 8 reactions ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
spyoungtech/FreeSimpleGUI#99 · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
spyoungtech/FreeSimpleGUI#95 ·
All issues in spyoungtech/FreeSimpleGUI
Similar issues
-
bug ci good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 Half a day Newbie friendliness 62/100
inmanta/inmanta-core#10835 ·
-
sponsored
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Diaoul/subliminal#1382 ·