Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/test/test_tkinter/widget_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def checkParam(self, widget, name, value, *, expected=_sentinel,
t = widget.configure(name)
self.assertEqual(len(t), 5)
self.assertEqual2(t[4], expected, eq=eq)
self.assertEqual(name in widget, True)
self.assertEqual("invalid-option-tkinter" in widget, False)

def checkInvalidParam(self, widget, name, value, errmsg=None):
orig = widget[name]
Expand Down
23 changes: 19 additions & 4 deletions Lib/tkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1845,10 +1845,18 @@ def configure(self, cnf=None, **kw):

def cget(self, key):
"""Return the current value of the configuration option."""
return self.tk.call(self._w, 'cget', '-' + key)
return self.tk.call(self._w, 'cget', f'-{key}')

__getitem__ = cget

def __contains__(self, option):
"""Check if the given option exists in this widget"""
try:
self.cget(option)
return True
except TclError:
return False

def __setitem__(self, key, value):
self.configure({key: value})

Expand Down Expand Up @@ -4322,11 +4330,18 @@ def blank(self):

def cget(self, option):
"""Return the value of OPTION."""
return self.tk.call(self.name, 'cget', '-' + option)
return self.tk.call(self.name, 'cget', f'-{option}')
# XXX config

def __getitem__(self, key):
return self.tk.call(self.name, 'cget', '-' + key)
__getitem__ = cget

def __contains__(self, option):
"""Check if the given option exists in this widget"""
try:
self.cget(option)
return True
except TclError:
return False

def copy(self, *, from_coords=None, zoom=None, subsample=None):
"""Return a new PhotoImage with the same image as this widget.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixed misleading error and added ``__contain__`` method in ``tkinter.Misc``
Loading