spyoungtech / spyoungtech/FreeSimpleGUI
Feature request: Enable detection of window minimised state
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 867
- Forks
- 106
- Avg merge
- 1m
- Merged PRs (30d)
- 2
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()
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.
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.
Assessment
- Tech stack
- python
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 39/100