Skip to content

Commit f3b1578

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

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
@@ -218,6 +218,10 @@ class Event:
218218
type - type of the event as a number
219219
widget - widget in which the event occurred
220220
delta - delta of wheel movement (MouseWheel)
221+
detail - certain fixed strings (see tcl/tk documentation)
222+
(Enter, Leave, FocusIn, FocusOut, ConfigureRequest)
223+
user_data - data string which was passed to event_generate or empty string
224+
(VirtualEvent)
221225
"""
222226
def __repr__(self):
223227
attrs = {k: v for k, v in self.__dict__.items() if v != '??'}
@@ -1378,7 +1382,7 @@ def _root(self):
13781382
w = self
13791383
while w.master: w = w.master
13801384
return w
1381-
_subst_format = ('%#', '%b', '%f', '%h', '%k',
1385+
_subst_format = ('%#', '%b', '%d', '%f', '%h', '%k',
13821386
'%s', '%t', '%w', '%x', '%y',
13831387
'%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y', '%D')
13841388
_subst_format_str = " ".join(_subst_format)
@@ -1395,11 +1399,14 @@ def getint_event(s):
13951399
except (ValueError, TclError):
13961400
return s
13971401

1398-
nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y, D = args
1399-
# Missing: (a, c, d, m, o, v, B, R)
1402+
nsign, b, d, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y, D = args
1403+
# Missing: (a, c, m, o, v, B, R)
14001404
e = Event()
14011405
# serial field: valid for all events
14021406
# number of button: ButtonPress and ButtonRelease events only
1407+
# detail: for Enter, Leave, FocusIn, FocusOut and ConfigureRequest
1408+
# events certain fixed strings (see tcl/tk documentation)
1409+
# user_data: data string from a virtual event or an empty string
14031410
# height field: Configure, ConfigureRequest, Create,
14041411
# ResizeRequest, and Expose events only
14051412
# keycode field: KeyPress and KeyRelease events only
@@ -1413,6 +1420,8 @@ def getint_event(s):
14131420
# KeyRelease, and Motion events
14141421
e.serial = getint(nsign)
14151422
e.num = getint_event(b)
1423+
e.user_data = d
1424+
e.detail = d
14161425
try: e.focus = getboolean(f)
14171426
except TclError: pass
14181427
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)