Skip to content

Commit 3ab440a

Browse files
committed
bpo-3405: Add support for user data of Tk virtual events in tkinter (%d substitution).
1 parent d50f01a commit 3ab440a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Lib/tkinter/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ class Event:
251251
type - type of the event as a number
252252
widget - widget in which the event occurred
253253
delta - delta of wheel movement (MouseWheel)
254+
detail - certain fixed strings (see tcl/tk documentation)
255+
(Enter, Leave, FocusIn, FocusOut, ConfigureRequest)
256+
user_data - data string which was passed to event_generate or empty string
257+
(VirtualEvent)
254258
"""
255259

256260
def __repr__(self):
@@ -1595,7 +1599,7 @@ def _root(self):
15951599
w = self
15961600
while w.master is not None: w = w.master
15971601
return w
1598-
_subst_format = ('%#', '%b', '%f', '%h', '%k',
1602+
_subst_format = ('%#', '%b', '%d', '%f', '%h', '%k',
15991603
'%s', '%t', '%w', '%x', '%y',
16001604
'%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y', '%D')
16011605
_subst_format_str = " ".join(_subst_format)
@@ -1613,11 +1617,14 @@ def getint_event(s):
16131617
except (ValueError, TclError):
16141618
return s
16151619

1616-
nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y, D = args
1617-
# Missing: (a, c, d, m, o, v, B, R)
1620+
nsign, b, d, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y, D = args
1621+
# Missing: (a, c, m, o, v, B, R)
16181622
e = Event()
16191623
# serial field: valid for all events
16201624
# number of button: ButtonPress and ButtonRelease events only
1625+
# detail: for Enter, Leave, FocusIn, FocusOut and ConfigureRequest
1626+
# events certain fixed strings (see tcl/tk documentation)
1627+
# user_data: data string from a virtual event or an empty string
16211628
# height field: Configure, ConfigureRequest, Create,
16221629
# ResizeRequest, and Expose events only
16231630
# keycode field: KeyPress and KeyRelease events only
@@ -1631,6 +1638,8 @@ def getint_event(s):
16311638
# KeyRelease, and Motion events
16321639
e.serial = getint(nsign)
16331640
e.num = getint_event(b)
1641+
e.user_data = d
1642+
e.detail = d
16341643
try: e.focus = getboolean(f)
16351644
except TclError: pass
16361645
e.height = getint_event(h)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for user data of Tk virtual events to :mod:`tkinter`.

0 commit comments

Comments
 (0)