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

gh-47655: Add support for user data of Tk virtual events to tkinter #7142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
serhiy-storchaka merged 9 commits into python:main from mkiever:bpo3405_event
Feb 25, 2026

Uh oh!

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

Merged

gh-47655: Add support for user data of Tk virtual events to tkinter #7142

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
9 commits
Select commit Hold shift + click to select a range
3ab440a
bpo-3405: Add support for user data of Tk virtual events in tkinter (…
mkiever May 13, 2018
bebae49
Tests added to test_tk for virtual events
mkiever May 20, 2018
36067fe
Also test for empty user_data
mkiever May 27, 2018
40b9f74
Merge branch 'main' into bpo3405_event
mkiever Sep 21, 2024
12bc426
Merge branch 'main' into bpo3405_event
serhiy-storchaka Jan 19, 2026
dd52032
Merge branch 'main' into bpo3405_event
serhiy-storchaka Feb 24, 2026
0ec1de1
Rewrite tests.
serhiy-storchaka Feb 24, 2026
e3e3cd0
Only set user_data for virtual events and detail for corresponding ev…
serhiy-storchaka Feb 24, 2026
67ee37a
Update docs.
serhiy-storchaka Feb 24, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

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

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

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

Diff view
Diff view

There are no files selected for viewing

5 changes: 5 additions & 0 deletions 5 Doc/whatsnew/3.15.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,11 @@ tkinter
with outdated names.
(Contributed by Serhiy Storchaka in :gh:`143754`.)

* Added :class:`!Event` attributes :attr:`!user_data` for Tk virtual events
and :attr:`!detail` for ``Enter``, ``Leave``, ``FocusIn``, ``FocusOut``,
and ``ConfigureRequest`` events.
(Contributed by Matthias Kievernagel and Serhiy Storchaka in :gh:`47655`.)


.. _whatsnew315-tomllib-1-1-0:

Expand Down
32 changes: 31 additions & 1 deletion 32 Lib/test/test_tkinter/test_misc.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ def test_focus(self):
self.assertEqual(e.x_root, '??')
self.assertEqual(e.y_root, '??')
self.assertEqual(e.delta, 0)
self.assertEqual(e.user_data, '??')
self.assertEqual(e.detail, 'NotifyAncestor')
self.assertEqual(repr(e), '<FocusIn event>')

def test_configure(self):
Expand Down Expand Up @@ -669,6 +671,8 @@ def test_configure(self):
self.assertEqual(e.x_root, '??')
self.assertEqual(e.y_root, '??')
self.assertEqual(e.delta, 0)
self.assertEqual(e.user_data, '??')
self.assertEqual(e.detail, '??')
self.assertEqual(repr(e), '<Configure event x=0 y=0 width=150 height=100>')

def test_event_generate_key_press(self):
Expand Down Expand Up @@ -705,6 +709,8 @@ def test_event_generate_key_press(self):
self.assertEqual(e.x_root, -1)
self.assertEqual(e.y_root, -1)
self.assertEqual(e.delta, 0)
self.assertEqual(e.user_data, '??')
self.assertEqual(e.detail, '??')
self.assertEqual(repr(e),
f"<KeyPress event state={e.state:#x} "
f"keysym=z keycode={e.keycode} char='z' x={e.x} y={e.y}>")
Expand Down Expand Up @@ -740,8 +746,17 @@ def test_event_generate_enter(self):
self.assertEqual(e.x_root, 100 + f.winfo_rootx())
self.assertEqual(e.y_root, 50 + f.winfo_rooty())
self.assertEqual(e.delta, 0)
self.assertEqual(e.user_data, '??')
self.assertEqual(e.detail, 'NotifyAncestor')
self.assertEqual(repr(e), '<Enter event focus=False x=100 y=50>')

f.event_generate('<Enter>', x=100, y=50, detail='NotifyPointer')
self.assertEqual(len(events), 2, events)
e = events[1]
self.assertIs(e.type, tkinter.EventType.Enter)
self.assertEqual(e.user_data, '??')
self.assertEqual(e.detail, 'NotifyPointer')

def test_event_generate_button_press(self):
f = tkinter.Frame(self.root, width=150, height=100)
f.pack()
Expand Down Expand Up @@ -774,6 +789,8 @@ def test_event_generate_button_press(self):
self.assertEqual(e.x_root, f.winfo_rootx() + 100)
self.assertEqual(e.y_root, f.winfo_rooty() + 50)
self.assertEqual(e.delta, 0)
self.assertEqual(e.user_data, '??')
self.assertEqual(e.detail, '??')
self.assertEqual(repr(e), '<ButtonPress event num=1 x=100 y=50>')

def test_event_generate_motion(self):
Expand Down Expand Up @@ -808,6 +825,8 @@ def test_event_generate_motion(self):
self.assertEqual(e.x_root, f.winfo_rootx() + 100)
self.assertEqual(e.y_root, f.winfo_rooty() + 50)
self.assertEqual(e.delta, 0)
self.assertEqual(e.user_data, '??')
self.assertEqual(e.detail, '??')
self.assertEqual(repr(e), '<Motion event state=Button1 x=100 y=50>')

def test_event_generate_mouse_wheel(self):
Expand Down Expand Up @@ -842,9 +861,11 @@ def test_event_generate_mouse_wheel(self):
self.assertEqual(e.x_root, f.winfo_rootx() + 100)
self.assertEqual(e.y_root, f.winfo_rooty() + 50)
self.assertEqual(e.delta, -5)
self.assertEqual(e.user_data, '??')
self.assertEqual(e.detail, '??')
self.assertEqual(repr(e), '<MouseWheel event delta=-5 x=100 y=50>')

def test_generate_event_virtual_event(self):
def test_event_generate_virtual_event(self):
f = tkinter.Frame(self.root, width=150, height=100)
f.pack()
self.root.wait_visibility() # needed on Windows
Expand Down Expand Up @@ -876,9 +897,18 @@ def test_generate_event_virtual_event(self):
self.assertEqual(e.x_root, f.winfo_rootx() + 50)
self.assertEqual(e.y_root, -1)
self.assertEqual(e.delta, 0)
self.assertEqual(e.user_data, '')
self.assertEqual(e.detail, '??')
self.assertEqual(repr(e),
f"<VirtualEvent event x=50 y=0>")

f.event_generate('<<Spam>>', data='spam')
self.assertEqual(len(events), 2, events)
e = events[1]
self.assertIs(e.type, tkinter.EventType.VirtualEvent)
self.assertEqual(e.user_data, 'spam')
self.assertEqual(e.detail, '??')


class BindTest(AbstractTkTest, unittest.TestCase):

Expand Down
21 changes: 17 additions & 4 deletions 21 Lib/tkinter/__init__.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ class Event:
type - type of the event as a number
widget - widget in which the event occurred
delta - delta of wheel movement (MouseWheel)
detail - certain fixed strings (see Tcl/Tk documentation)
(Enter, Leave, FocusIn, FocusOut, ConfigureRequest)
user_data - data string which was passed to event_generate() or empty
string (VirtualEvent)
"""

def __repr__(self):
Expand Down Expand Up @@ -1538,7 +1542,7 @@ def bind(self, sequence=None, func=None, add=None):
<Alt-A> for pressing A and the Alt key (KeyPress can be omitted).
An event pattern can also be a virtual event of the form
<<AString>> where AString can be arbitrary. This
event can be generated by event_generate.
event can be generated by event_generate().
If events are concatenated they must appear shortly
after each other.

Expand Down Expand Up @@ -1723,7 +1727,7 @@ def _root(self):
w = self
while w.master is not None: w = w.master
return w
_subst_format = ('%#', '%b', '%f', '%h', '%k',
_subst_format = ('%#', '%b', '%d', '%f', '%h', '%k',
'%s', '%t', '%w', '%x', '%y',
'%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y', '%D')
_subst_format_str = " ".join(_subst_format)
Expand All @@ -1744,11 +1748,14 @@ def getint_event(s):
if any(isinstance(s, tuple) for s in args):
args = [s[0] if isinstance(s, tuple) and len(s) == 1 else s
for s in args]
nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y, D = args
# Missing: (a, c, d, m, o, v, B, R)
nsign, b, d, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y, D = args
Comment thread
serhiy-storchaka marked this conversation as resolved.
Resolved

Uh oh!

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

# Missing: (a, c, m, o, v, B, R)
e = Event()
# serial field: valid for all events
# number of button: ButtonPress and ButtonRelease events only
# detail: for Enter, Leave, FocusIn, FocusOut and ConfigureRequest
# events certain fixed strings (see Tcl/Tk documentation)
# user_data: data string from a virtual event or an empty string
# height field: Configure, ConfigureRequest, Create,
# ResizeRequest, and Expose events only
# keycode field: KeyPress and KeyRelease events only
Expand All @@ -1762,6 +1769,12 @@ def getint_event(s):
# KeyRelease, and Motion events
e.serial = getint(nsign)
e.num = getint_event(b)
if T == EventType.VirtualEvent:
e.user_data = d
e.detail = '??'
else:
e.user_data = '??'
e.detail = d
try: e.focus = getboolean(f)
except TclError: pass
e.height = getint_event(h)
Expand Down
3 changes: 3 additions & 0 deletions 3 Misc/NEWS.d/next/Library/2018-05-11-12-26-16.bpo-3405.CacMw9.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add support for user data of Tk virtual events and detail for
``Enter``, ``Leave``, ``FocusIn``, ``FocusOut``, and
``ConfigureRequest`` events to :mod:`tkinter`.
Loading
Oops, something went wrong.

Uh oh!

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

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.