Skip to content

Commit f8ebb7b

Browse files
bpo-41831: Restore str implementation of __str__ in tkinter.EventType (GH-22355)
(cherry picked from commit eb38c6b) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 8693854 commit f8ebb7b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Lib/tkinter/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ class EventType(str, enum.Enum):
185185
Deactivate = '37'
186186
MouseWheel = '38'
187187

188-
def __str__(self):
189-
return self.name
188+
__str__ = str.__str__
190189

191190

192191
class Event:
@@ -266,7 +265,7 @@ def __repr__(self):
266265
'num', 'delta', 'focus',
267266
'x', 'y', 'width', 'height')
268267
return '<%s event%s>' % (
269-
self.type,
268+
getattr(self.type, 'name', self.type),
270269
''.join(' %s=%s' % (k, attrs[k]) for k in keys if k in attrs)
271270
)
272271

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``str()`` for the ``type`` attribute of the ``tkinter.Event`` object always
2+
returns now the numeric code returned by Tk instead of the name of the event
3+
type.

0 commit comments

Comments
 (0)