cpython/Lib/test/test_tkinter
Serhiy Storchaka 159a3604b9
[3.13] gh-157672: Keep Python's signal handlers when Tk is initialized on macOS (GH-157673) (GH-157989)
Tk on macOS replaces the SIGINT, SIGHUP and SIGTERM handlers with its
own, which exits the process, so Ctrl-C terminated a tkinter program
instead of raising KeyboardInterrupt.  Save the handlers installed by
Python before Tk_Init() and restore them after it.

This affects Tk 8.6.11 to 8.6.18 and 9.0 to 9.0.4.  Tk itself is fixed
in 8.6.19 and 9.0.5.

(cherry picked from commit 4532b36db5)

On 3.13 there was no Tkinter_TkInit(), and tkappinit.c, which is used
when Python is built with WITH_APPINIT (as on macOS), called Tk_Init()
directly, bypassing the fix.
2026-09-23 11:40:46 +00:00
..
__init__.py
__main__.py
README
support.py [3.13] gh-154357: Fix tkinter, ttk and IDLE tests depending on the window manager (GH-154370) (GH-157065) 2026-09-07 17:06:10 +03:00
test_colorchooser.py
test_dnd.py
test_filedialog.py [3.13] gh-154357: Fix tkinter, ttk and IDLE tests depending on the window manager (GH-154370) (GH-157065) 2026-09-07 17:06:10 +03:00
test_font.py [3.13] gh-156961: Fix tkinter.font.Font for a font name returned as a Tcl object (GH-157028) (GH-157405) 2026-09-13 08:25:18 +00:00
test_geometry_managers.py
test_images.py
test_loadtk.py
test_messagebox.py
test_misc.py [3.13] gh-157672: Keep Python's signal handlers when Tk is initialized on macOS (GH-157673) (GH-157989) 2026-09-23 11:40:46 +00:00
test_scrolledtext.py
test_simpledialog.py [3.13] gh-154357: Fix tkinter, ttk and IDLE tests depending on the window manager (GH-154370) (GH-157065) 2026-09-07 17:06:10 +03:00
test_text.py
test_tkinter_pipe.py
test_variables.py
test_widgets.py
widget_tests.py

Writing new tests
=================

Precaution
----------

    New tests should always use only one Tk window at once, like all the
    current tests do. This means that you have to destroy the current window
    before creating another one, and clean up after the test. The motivation
    behind this is that some tests may depend on having its window focused
    while it is running to work properly, and it may be hard to force focus
    on your window across platforms (right now only test_traversal at
    test_ttk.test_widgets.NotebookTest depends on this).