Python 3.7.13 macOS: tk.h version (8.6) doesn't match libtk.a version (8.5)

Description:
There seems to be a mistmatch between the tkinter versions with Python 3.7 on macOS.

Action version:
v3
Which at the time of writting is v3.1.2

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version:

  • Python 3.7
    • Specically 3.7.13
  • Current runner version: '2.291.1'
    • macOS (latest) 11.6.5 20G527

Repro steps:

This simple script opens a tkinter window and closes it after 5 seconds:

import tkinter as tk

root = tk.Tk()
label = tk.Label(root, text="Hello World!")
label.pack(padx=20, pady=20)
root.after(5000, root.destroy)    # Close the Window after 5 seconds
root.mainloop()

With this workflow:

name: Test Python Tk

on: [push, pull_request]

jobs:
  tests-poetry:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
      fail-fast: false
    name: Py ${{ matrix.python-version }} - ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v3
        with:
          python-version: ${{ matrix.python-version }}
      - name: Prepare Ubuntu xvfb
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y libxkbcommon-x11-0 xvfb
      - name: Run tk script (closes itself after 5 seconds) - Ubuntu
        if: runner.os == 'Linux'
        run: xvfb-run python tk_min.py
      - name: Run tk script (closes itself after 5 seconds)
        if: runner.os != 'Linux'
        run: python tk_min.py

Works in all Python versions and operating systems except 3.7 on macOS:

image

Expected behavior:
The Python script to run without throwing an exception

Actual behavior:
An exception thrown by Python:

 Traceback (most recent call last):
  File "tk_min.py", line 9, in <module>
    root = tk.Tk()
  File "/Users/runner/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/tkinter/__init__.py", line 2025, in __init__
    self._loadtk()
  File "/Users/runner/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/tkinter/__init__.py", line 2040, in _loadtk
    % (_tkinter.TK_VERSION, tk_version))
RuntimeError: tk.h version (8.6) doesn't match libtk.a version (8.5)