Original file line numberDiff line numberDiff line change@@ -2016,6 +2016,16 @@ If you don't know the class name of a widget, use the method
20162016 Returns a tuple of all known themes.
20172017201820182019+ .. method:: theme_styles(themename=None)
2020+2021+ Returns a tuple of all styles in *themename*.
2022+ If *themename* is not given, the current theme is used.
2023+2024+ .. versionadded:: next
2025+2026+ Availability: Tk 9.0.
2027+2028+20192029 .. method:: theme_use(themename=None)
2020203020212031 If *themename* is not given, returns the theme in use. Otherwise, sets
Original file line numberDiff line numberDiff line change@@ -173,6 +173,11 @@ tkinter
173173 synchronization of the displayed view with the underlying text.
174174 (Contributed by Serhiy Storchaka in :gh:`151675`.)
175175176+* Added the :meth:`ttk.Style.theme_styles
177+ <tkinter.ttk.Style.theme_styles>` method which returns the list of styles
178+ defined in a theme.
179+ (Contributed by Serhiy Storchaka in :gh:`151920`.)
180+176181* Added new :class:`!tkinter.Canvas` methods :meth:`~tkinter.Canvas.rchars`
177182 which replaces the text or coordinates of canvas items, and
178183:meth:`~tkinter.Canvas.rotate` which rotates the coordinates of canvas items.
@@ -211,7 +216,6 @@ tkinter
211216 dithered image when its data was supplied in pieces.
212217 (Contributed by Serhiy Storchaka in :gh:`151888`.)
213218214-215219xml
216220---
217221Original file line numberDiff line numberDiff line change@@ -6,7 +6,8 @@
66fromtestimportsupport
77fromtest.supportimportrequires
88fromtest.test_tkinter.supportimportsetUpModule# noqa: F401
9-fromtest.test_tkinter.supportimportAbstractTkTest, get_tk_patchlevel
9+fromtest.test_tkinter.supportimport (AbstractTkTest, get_tk_patchlevel,
10+requires_tk)
10111112requires('gui')
1213@@ -124,6 +125,25 @@ def test_theme_use(self):
124125125126self.style.theme_use(curr_theme)
126127128+@requires_tk(9, 0)
129+deftest_theme_styles(self):
130+# The 'default' theme is always available and defines the base styles.
131+default_styles=self.style.theme_styles('default')
132+self.assertIsInstance(default_styles, tuple)
133+self.assertIn('.', default_styles)
134+self.assertIn('TButton', default_styles)
135+136+# Without an argument the current theme is used.
137+styles=self.style.theme_styles()
138+self.assertIsInstance(styles, tuple)
139+self.assertIn('.', styles)
140+141+forthemeinself.style.theme_names():
142+self.assertIsInstance(self.style.theme_styles(theme), tuple)
143+144+self.assertRaises(tkinter.TclError,
145+self.style.theme_styles, 'nonexistingname')
146+127147deftest_theme_settings(self):
128148style=self.style
129149theme=style.theme_use()
Original file line numberDiff line numberDiff line change@@ -492,6 +492,20 @@ def theme_names(self):
492492returnself.tk.splitlist(self.tk.call(self._name, "theme", "names"))
493493494494495+deftheme_styles(self, themename=None):
496+"""Returns a list of all styles in themename.
497+498+ If themename is omitted, the current theme is used.
499+500+ Availability: Tk 9.0.
501+ """
502+ifthemenameisNone:
503+returnself.tk.splitlist(
504+self.tk.call(self._name, "theme", "styles"))
505+returnself.tk.splitlist(
506+self.tk.call(self._name, "theme", "styles", themename))
507+508+495509deftheme_use(self, themename=None):
496510"""If themename is None, returns the theme in use, otherwise, set
497511 the current theme to themename, refreshes all widgets and emits
Original file line numberDiff line numberDiff line change@@ -0,0 +1,3 @@
1+Add the :meth:`ttk.Style.theme_styles <tkinter.ttk.Style.theme_styles>`
2+method, wrapping the Tk ``ttk::style theme styles`` subcommand, which
3+returns the list of styles defined in a theme.