FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-59396: Add use_ttk parameter to tkinter ScrolledText by serhiy-storchaka · Pull Request #153119 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (3) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 10 additions & 1 deletion Doc/library/tkinter.scrolledtext.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ most normal geometry management behavior.
Should more specific control be necessary, the following attributes are
available:

.. class:: ScrolledText(master=None, **kw)
.. class:: ScrolledText(master=None, *, use_ttk=False, **kw)

The keyword arguments are passed to the :class:`~tkinter.Text` widget.

When *use_ttk* is true, the surrounding frame and the scroll bar are the
themed :mod:`tkinter.ttk` widgets;
the default is the classic :mod:`tkinter` widgets.

.. versionchanged:: next
Added the *use_ttk* parameter.


.. attribute:: frame
Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.16.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ tkinter
them.
(Contributed by Serhiy Storchaka in :gh:`59396`.)

* :class:`tkinter.scrolledtext.ScrolledText` gained a *use_ttk* parameter to use
the themed :mod:`tkinter.ttk` frame and scroll bar instead of the classic
:mod:`tkinter` widgets.
(Contributed by Serhiy Storchaka in :gh:`59396`.)

* :class:`tkinter.font.Font` can now wrap a font description without creating a
new named font, by passing it as *font* with ``exists=True`` and no *name*.
This avoids a loss of precision in :meth:`~tkinter.font.Font.actual`,
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_tkinter/test_scrolledtext.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import tkinter
from tkinter import ttk
from tkinter.scrolledtext import ScrolledText
from test.support import requires
from test.test_tkinter.support import setUpModule # noqa: F401
Expand All @@ -19,15 +20,24 @@ def test_create(self):
st = self.create(background='red', height=5)
# It is a Text widget held in a Frame together with a Scrollbar.
self.assertIsInstance(st, tkinter.Text)
# By default the frame and scroll bar are the classic tkinter widgets.
self.assertIsInstance(st.frame, tkinter.Frame)
self.assertNotIsInstance(st.frame, ttk.Frame)
self.assertIsInstance(st.vbar, tkinter.Scrollbar)
self.assertNotIsInstance(st.vbar, ttk.Scrollbar)
self.assertEqual(st.winfo_parent(), str(st.frame))
# str() returns the frame, so that geometry managers manage it.
self.assertEqual(str(st), str(st.frame))
# Keyword options configure the Text.
self.assertEqual(str(st['background']), 'red')
self.assertEqual(st['height'], 5 if self.wantobjects else '5')

def test_use_ttk(self):
# use_ttk=True uses the themed tkinter.ttk widgets.
st = self.create(use_ttk=True)
self.assertIsInstance(st.frame, ttk.Frame)
self.assertIsInstance(st.vbar, ttk.Scrollbar)

def test_text_methods(self):
st = self.create()
st.insert('1.0', 'hello\nworld')
Expand Down
15 changes: 11 additions & 4 deletions Lib/tkinter/scrolledtext.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@
the Scrollbar widget.
Most methods calls are inherited from the Text widget; Pack, Grid and
Place methods are redirected to the Frame widget however.

Pass use_ttk=True for the themed tkinter.ttk frame and scroll bar
instead of the classic tkinter widgets.
"""

from tkinter import Frame, Text, Scrollbar, Pack, Grid, Place
from tkinter import Frame, Text, Scrollbar, Pack, Grid, Place, ttk
from tkinter.constants import RIGHT, LEFT, Y, BOTH

__all__ = ['ScrolledText']


class ScrolledText(Text):
def __init__(self, master=None, **kw):
self.frame = Frame(master)
self.vbar = Scrollbar(self.frame)
def __init__(self, master=None, *, use_ttk=False, **kw):
if use_ttk:
self.frame = ttk.Frame(master)
self.vbar = ttk.Scrollbar(self.frame)
else:
self.frame = Frame(master)
self.vbar = Scrollbar(self.frame)
self.vbar.pack(side=RIGHT, fill=Y)

kw['yscrollcommand'] = self.vbar.set
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:class:`tkinter.scrolledtext.ScrolledText` gained a *use_ttk* parameter to use
the themed :mod:`tkinter.ttk` frame and scroll bar instead of the classic
:mod:`tkinter` widgets.
Loading

Back | FazBrowse Home | New Git URL