Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-100814: Fix exception for invalid callable value of Tkinter image option #107692

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.

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
Merged
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
16 changes: 16 additions & 0 deletions Lib/test/test_tkinter/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ def test_configure_foreground(self):
self.assertEqual(image['foreground'],
'-foreground {} {} #000000 yellow')

def test_bug_100814(self):
# gh-100814: Passing a callable option value causes AttributeError.
with self.assertRaises(tkinter.TclError):
tkinter.BitmapImage('::img::test', master=self.root, spam=print)
image = tkinter.BitmapImage('::img::test', master=self.root)
with self.assertRaises(tkinter.TclError):
image.configure(spam=print)


class PhotoImageTest(AbstractTkTest, unittest.TestCase):

Expand Down Expand Up @@ -274,6 +282,14 @@ def test_configure_palette(self):
image.configure(palette='3/4/2')
self.assertEqual(image['palette'], '3/4/2')

def test_bug_100814(self):
# gh-100814: Passing a callable option value causes AttributeError.
with self.assertRaises(tkinter.TclError):
tkinter.PhotoImage('::img::test', master=self.root, spam=print)
image = tkinter.PhotoImage('::img::test', master=self.root)
with self.assertRaises(tkinter.TclError):
image.configure(spam=print)

def test_blank(self):
image = self.create()
image.blank()
Expand Down
4 changes: 0 additions & 4 deletions Lib/tkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4069,8 +4069,6 @@ def __init__(self, imgtype, name=None, cnf={}, master=None, **kw):
elif kw: cnf = kw
options = ()
for k, v in cnf.items():
if callable(v):
v = self._register(v)
options = options + ('-'+k, v)
self.tk.call(('image', 'create', imgtype, name,) + options)
self.name = name
Expand All @@ -4097,8 +4095,6 @@ def configure(self, **kw):
for k, v in _cnfmerge(kw).items():
if v is not None:
if k[-1] == '_': k = k[:-1]
if callable(v):
v = self._register(v)
res = res + ('-'+k, v)
self.tk.call((self.name, 'config') + res)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Passing a callable object as an option value to a Tkinter image now raises
the expected TclError instead of an AttributeError.