GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-47655: Add support for user data of Tk virtual events to tkinter by mkiever · Pull Request #7142 · python/cpython

Conversation

@mkiever

@mkiever mkiever commented May 27, 2018 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This adds Tk %d event field as 'detail' and 'user_data' attributes to tkinter events.

I have not yet changed the documentation, because I am not sure about the intent
of the table in "25.1.6.7. Bindings and Events" in tkinter documentation.
If supposed to be complete, I suggest also adding the other three missing fields (%#, %b, %D).

I have added a simple test of virtual events and the userdata attribute including bind/unbind.
To make the test possible I use a pump_events function found on
stackoverflow (https://stackoverflow.com/questions/4083796/how-do-i-run-unittest-on-a-tkinter-app/49028688#49028688).
Note, I tested this only on Debian Linux.
Also, I had spurious "Bad Drawable" errors from the X server running the tkinter unittest,
but I have those in the same way on the changed and unchanged Python.
Seems to be my non-mainstream setup (ctwm with interactive window placement).

This is my first pull request. Sorry, if I have forgotten obvious things.

https://bugs.python.org/issue3405

  • Issue: Add support for the new data option supported by event generate (Tk 8.5) #47655

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JRiggles, sandyscott, and koutoftimer reacted with thumbs up emoji James-E-A and koutoftimer reacted with heart emoji
All reactions
  • 👍 3 reactions
  • ❤️ 2 reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA not signed label May 27, 2018
@the-knights-who-say-ni

the-knights-who-say-ni commented May 27, 2018

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

When your account is ready, please add a comment in this pull request
and a Python core developer will remove the CLA not signed label
to make the bot check again.

Thanks again to your contribution and we look forward to looking at it!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added the awaiting review label May 27, 2018
@mkiever

mkiever commented Jun 8, 2018

Copy link
Copy Markdown
Contributor Author

I see a "Contributor Form Received: Yes" now on my account on bpo. So CLA has arrived.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@taleinat taleinat added CLA signed and removed CLA not signed labels Jun 12, 2018
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Jun 12, 2018
@csabella
csabella requested a review from serhiy-storchaka May 18, 2019 12:12
@koutoftimer

koutoftimer commented Jun 17, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

@the-knights-who-say-ni , what is missing? Why it is not accepted yet?

ERROR: test_ignore (test.test_multiprocessing_forkserver.TestIgnoreEINTR)
FAIL: test_stdin_broken_pipe (test.test_asyncio.test_subprocess.SubprocessSafeWatcherTests)

Those erros are not related to tkinter

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

koutoftimer
koutoftimer approved these changes Jun 17, 2020
View reviewed changes

@koutoftimer koutoftimer left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified for Python 3.7.3 win64.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting core review and removed awaiting review labels Jun 17, 2020
@aleroddepaz

aleroddepaz commented Apr 30, 2022

Copy link
Copy Markdown

I have not seen any news about this issue after the migration, but it looks like this is the most complete patch. @serhiy-storchaka could anything else be done to help with this review?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ezio-melotti ezio-melotti removed the CLA signed label Jul 13, 2022
mkiever added 3 commits April 27, 2023 21:18
@mkiever
bpo-3405: Add support for user data of Tk virtual events in tkinter (…
3ab440a
…%d substitution).
@mkiever
Tests added to test_tk for virtual events
bebae49
@mkiever
Also test for empty user_data
36067fe
@mkiever
mkiever force-pushed the bpo3405_event branch from c74d372 to 36067fe Compare April 27, 2023 21:18
@gpolo gpolo mannequin mentioned this pull request Nov 23, 2023
Add support for the new data option supported by event generate (Tk 8.5) #47655
Closed
@github-actions

github-actions Bot commented Sep 21, 2024

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Sep 21, 2024
@mkiever
Merge branch 'main' into bpo3405_event
40b9f74
koutoftimer
koutoftimer reviewed Sep 24, 2024
View reviewed changes
Comment thread Lib/tkinter/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Dec 15, 2024
@picnixz picnixz changed the title bpo-3405: Add support for user data of Tk virtual events to tkinter gh-47655: Add support for user data of Tk virtual events to tkinter Dec 15, 2024
@github-actions

github-actions Bot commented Feb 27, 2025

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Feb 27, 2025
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Apr 9, 2025
@github-actions

github-actions Bot commented May 10, 2025

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 10, 2025
@ZelphirKaltstahl

ZelphirKaltstahl commented Nov 15, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Any progress here? @serhiy-storchaka I think your review is requested?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Nov 15, 2025
@github-actions

github-actions Bot commented Dec 15, 2025

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Dec 15, 2025
@ZelphirKaltstahl

ZelphirKaltstahl commented Dec 15, 2025

Copy link
Copy Markdown

Ping.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Dec 16, 2025
@github-actions

github-actions Bot commented Jan 15, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Jan 15, 2026
@ZelphirKaltstahl

ZelphirKaltstahl commented Jan 15, 2026

Copy link
Copy Markdown

Ping.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jan 15, 2026
@serhiy-storchaka
Merge branch 'main' into bpo3405_event
12bc426
@serhiy-storchaka

serhiy-storchaka commented Jan 19, 2026

Copy link
Copy Markdown
Member

Thank you for reminder @ZelphirKaltstahl. I'm going to finish this. Sorry that it took so much time, @mkiever.

For now, I have the following comments:

  • Now there are tests for events in Lib/test/test_tkinter/test_misc.py. Please move new tests there, preferably following the style of the existing tests. Maybe it is enough to add few lines to existing tests.
  • This is the only substitution that is exposed as two fields. It may be confusing. Could we only set data for virtual events and detail for other events? BTW, since even generate uses -data, not -user_data, I think that the name data is more preferable.
  • There are other subsitutions, like %a and %i. Should they also be supported?

If you have no time, @mkiever, or lost interest, I'll continue this work, preserving your credits.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@koutoftimer

koutoftimer commented Jan 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

@serhiy-storchaka

BTW, since even generate uses -data, not -user_data, I think that the name data is more preferable.

man n event talks about user_data field. If you are about to change it to just data field of the event object it will cause additional friction.

There are also mentioning of detail field

Both user_data and detail should be, or at least behave as, object fields. It would be nice for the event object to have access to the args directly and perform substitution lazily. Anyway, because %d corresponds to 2 different fields the question of "single source of truth arrives". I'd prefer implementation with lazy field access or some private __d variable that corresponds to substitution with @property. And type checking to prevent access to user_data and detail fields (if they act as union). This issue has to be resolved or it is technical dept.

The data you are referring to is more like "argument name for the event constructor", not the name of the field of the event object itself.

UPD: WidgetViewSync is one of the predefined virtual events but it has detail field instead of user_data.

       <<WidgetViewSync>>
              This is sent to a text widget when its internal data become obsolete, and again when these
              internal data are back in sync with the widget view. The detail field (%d substitution) is
              either true (when the widget is in sync) or false (when it is not).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Jan 19, 2026

Copy link
Copy Markdown
Member

Well, lets keep user_data. There is already precedence -- send_event, x_root. These names are field names in the XEvent union.

As for the WidgetViewSync event, this is an error in the documentation. All virtual events have field user_data, not detail. You can look at the code of GenerateWidgetViewSyncEvent and Tk_SendVirtualEvent for generating the event and
at the code of ExpandPercents in generic/tkBind.c for substitution:

	case 'd':
	    if (flags & (CROSSING|FOCUS)) {
		int detail = (flags & FOCUS) ? evPtr->xfocus.detail : evPtr->xcrossing.detail;
		string = TkFindStateString(notifyDetail, detail);
	    } else if (flags & CONFIGREQ) {
		if (evPtr->xconfigurerequest.value_mask & CWStackMode) {
		    string = TkFindStateString(configureRequestDetail, evPtr->xconfigurerequest.detail);
		} else {
		    string = "";
		}
	    } else if (flags & VIRTUAL) {
		XVirtualEvent *vePtr = (XVirtualEvent *) evPtr;
		string = vePtr->user_data ? Tcl_GetString(vePtr->user_data) : "";
	    }
	    break;
koutoftimer reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@koutoftimer

koutoftimer commented Jan 19, 2026

Copy link
Copy Markdown

These names are field names in the XEvent union.

If you are talking about this XEvent all fields are hidden behind respected event types, send_event and x_root aren't exposed directly.

As for class Event it can be just a dictionary. It would be nice to have inheritance similar to XEvent (abstract class) with XKeymapEvent etc. as concrete implementations (proper inheritance would allow to use object.__slots__) but it is not the scope of this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Jan 24, 2026

Copy link
Copy Markdown
Member

Yes, this XEvent. It is a union of different structs that correspond different event types. Each substitution usually corresponds to fields with the same name in different structures. Except "%d", which correspond to detail or user_data, depending on the event type. So, I think that %d should be mapped back to either detail or user_data field of tkinter.Event depending on the event type.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Feb 23, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Feb 23, 2026
serhiy-storchaka added 4 commits February 24, 2026 18:38
@serhiy-storchaka
Merge branch 'main' into bpo3405_event
dd52032
@serhiy-storchaka
Rewrite tests.
0ec1de1
@serhiy-storchaka
Only set user_data for virtual events and detail for corresponding ev…
e3e3cd0
…ents.
@serhiy-storchaka
Update docs.
67ee37a
@serhiy-storchaka
serhiy-storchaka requested a review from AA-Turner as a code owner February 24, 2026 17:39
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Feb 24, 2026
@serhiy-storchaka
serhiy-storchaka merged commit f8ce51a into python:main Feb 25, 2026
47 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting core review label Feb 25, 2026
brijkapadia pushed a commit to brijkapadia/cpython that referenced this pull request Feb 28, 2026
@mkiever @serhiy-storchaka @brijkapadia
pythongh-47655: Add support for user data and detail of Tk events to …
e68a542
…tkinter (pythonGH-7142)

Expose the %d substitution as the tkinter.Event attributes:

* "detail" for Enter, Leave, FocusIn, FocusOut, and ConfigureRequest events
* "user_data" for virtual events

Co-authored-by: Serhiy Storchaka <[email protected]>
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@mkiever @serhiy-storchaka @ljfp
pythongh-47655: Add support for user data and detail of Tk events to …
313f063
…tkinter (pythonGH-7142)

Expose the %d substitution as the tkinter.Event attributes:

* "detail" for Enter, Leave, FocusIn, FocusOut, and ConfigureRequest events
* "user_data" for virtual events

Co-authored-by: Serhiy Storchaka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka Awaiting requested review from serhiy-storchaka
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
1 more reviewer
@koutoftimer koutoftimer koutoftimer approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@mkiever @the-knights-who-say-ni @koutoftimer @aleroddepaz @ZelphirKaltstahl @serhiy-storchaka @taleinat @ezio-melotti @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.