Skip to content

Conversation

mdehoon
Copy link
Contributor

@mdehoon mdehoon commented Oct 15, 2025

When using tkinter in an interactive Python session, the EventHook function in Modules/_tkinter.c runs the Tcl/Tk event loop, and exits once data becomes available on stdin (i.e., when the user types in the next Python command).

The EventHook function monitors for input on stdin using Tcl_CreateFileHandler.

As Tcl_CreateFileHandler is Unix-only, for Windows instead the _kbhit function from Microsoft Windows is used.

However, this prevents stdin from being used with a pipe (see Issue #140146 ), as _kbhit checks for a keystroke on an actual keyboard.

This PR replaces Tcl_CreateFileHandler by Tcl_CreateChannelHandler and Tcl_GetStdChannel(TCL_STDIN), which do not depend on platform.

This has two advantages:

  1. It allows stdin to be used as a pipe on all platforms, which is useful for testing interactive usage of tkinter;
  2. We can get rid of some Windows-specific code in Modules/_tkinter.c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant