Skip to content
5 changes: 5 additions & 0 deletions Lib/test/test_ttk/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ def test_cb(arg1, **kw):
self.widget.state(['active', '!disabled'])
self.assertEqual(self.widget.state(), ('active', ))

def test_widget_cget(self):
# Check whether the return value of cget is a string
self.assertEqual(self.widget.cget("state"), tkinter.NORMAL)
self.assertEqual(self.widget.cget("text"), "Text")


class AbstractToplevelTest(AbstractWidgetTest, PixelSizeTests):
_rounds_pixels = False
Expand Down
11 changes: 11 additions & 0 deletions Lib/tkinter/ttk.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"tclobjs_to_py", "setup_master"]

import tkinter
import _tkinter
from tkinter import _flatten, _join, _stringify, _splitdict


Expand Down Expand Up @@ -572,6 +573,16 @@ def state(self, statespec=None):
return self.tk.splitlist(str(self.tk.call(self._w, "state", statespec)))


def cget(self, key):
Comment thread
Xiaokang2022 marked this conversation as resolved.
Resolved
"""Return the resource value for a KEY given as string."""
return_value = super().cget(key)
if isinstance(return_value, _tkinter.Tcl_Obj):
return str(return_value)
return return_value

__getitem__ = cget


class Button(Widget):
"""Ttk Button widget, displays a textual label and/or image, and
evaluates a command when pressed."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix an incorrect return value type when getting resource value of ttk widgets.
Comment thread
Xiaokang2022 marked this conversation as resolved.
Resolved