PySimpleGUI / PySimpleGUI/PySimpleGUI

[Bug] MacOS - Clicking on the window's X button does not close the window if enable_close_attempted_event

Open
#4,880 19 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation Platform Specific Issue - Mac Port - TK
Dominant language
Python
Stars
13.8k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

Type of Issue (Enhancement, Error, Bug, Question)

Bug


Operating System

MacOS

PySimpleGUI Port (tkinter, Qt, Wx, Web)

Tkinter


Versions

Python version: 3.10.0 (v3.10.0:b494f5935c, Oct 4 2021, 14:59:20) [Clang 12.0.5 (clang-1205.0.22.11)]
port: tkinter
tkinter version: 8.6.11
PySimpleGUI version: 4.53.0
PySimpleGUI filename: /Users/Nacho/PycharmProjects/test/venv-3.10/lib/python3.10/site-packages/PySimpleGUI/PySimpleGUI.py


Your Experience In Months or Years (optional)

Years Python programming experience: 3 years

Years Programming experience overall: 20+ years

Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine): Qt

Anything else you think would be helpful?


Troubleshooting

These items may solve your problem. Please check those you've done by changing - [ ] to - [X]

  • Searched main docs for your problem www.PySimpleGUI.org
  • Looked for Demo Programs that are similar to your goal Demos.PySimpleGUI.org
  • If not tkinter - looked for Demo Programs for specific port
  • For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
  • Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released
Detailed Description

A sg.Window created with enable_close_attempted_event=True and that uses a timeout upon read like sg.Window.read(timeout=100), does not close when clicking the standard window X button.

This happens ONLY on tkinter 8.6.11 bundled with Python 3.10. If I switch to Python 3.9 (tkinter 8.6.8) the window closes fine.
I also tested this behavior on Windows and could not reproduce it on the latest tkinter on Python 3.10, but the latest there is < 8.6.11.

If I remove the timeout on the sg.Windows.read call, then the window closes fine. It is the combination of using sg.Window.read(timeout=100) and sg.Window(enable_close_attempted_event=True) and tkinter 8.6.11 what sees to cause this strange behavior.

Code To Duplicate

A short program that isolates and demonstrates the problem (Do not paste your massive program, but instead 10-20 lines that clearly show the problem)

This pre-formatted code block is all set for you to paste in your bit of code:

import PySimpleGUI as sg

window = sg.Window(title='Window',
                   enable_close_attempted_event=True,
                   layout=[[sg.Text(text='Test')],
                           [sg.CloseButton(button_text='Close')]])
while True:
    event, values = window.read(timeout=100)
    if event in ('Close', sg.WIN_CLOSED):
        break
    if event == sg.WINDOW_CLOSE_ATTEMPTED_EVENT:
        break
window.close()
Screenshot, Sketch, or Drawing

This is on Python 3.10 (tkinter 8.6.11):

https://user-images.githubusercontent.com/7527257/138787863-9262e42f-ef68-452d-b40a-b5bb4c3877e1.mov

This is on Python 3.9 (tkinter 8.6.8):

https://user-images.githubusercontent.com/7527257/138787938-63ffd69f-4861-423e-a8cc-a3fe05c1b1ec.mov


Watcha Makin?

If you care to share something about your project, it would be awesome to hear what you're building.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Window example on macOS with Python 3.10, tkinter 8.6.11, enable_close_attempted_event=True, and read(timeout=100), then compare it with Python 3.9 and tkinter 8.6.8. Trace the interaction between the timeout read and the window-close attempt; done means the standard X button produces the expected close event and the example exits.

Written by the indexing model from the issue text.

Assessment

Tech stack
macos, python
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.