简体中文 | English | More translations are welcome!
Themed Tkinter Text widget with modern styling support.
- 🎨 Theme-aware text widget that automatically adapts to ttk themes
- 📜 Built-in ScrolledText component with vertical/horizontal scrollbars
- 🖥️ Native integration with ttk styles and themes
- 🔄 Dynamic theme switching support
Example screenshots of Windows 11, Windows 10, and Windows 7.
You can install ttk-text using your preferred package manager.
Since ttk-text is currently unstable, I strongly recommend installing it in a virtual environment to avoid version conflicts.
# Using pip
pip install ttk-text
# Using uv
uv add ttk-text
# Using PDM
pdm add ttk-text
# Using Poetry
poetry add ttk-textttk-text provides two widgets:
ttk_text.ThemedText: A themed Text widget, as a replacement fortkinter.Text.ttk_text.scrolled_text.ScrolledText: An extension ofThemedTextwith vertical/horizontal scrollbars, as a replacement fortkinter.scrolledtext.ScrolledText.
You can use ThemedText and ScrolledText just like you would use tkinter.Text.
Here’s an example:
from tkinter import Tk
from ttk_text import ThemedText
from ttk_text.scrolled_text import ScrolledText
root = Tk()
themed_text = ThemedText(root)
themed_text.pack(fill="both", expand=True)
scrolled_text = ScrolledText(root)
scrolled_text.pack(fill="both", expand=True)
root.mainloop()The ThemedText component works by wrapping a Text widget inside a ttk Frame. This Frame uses the default style name ThemedText.TEntry, which you can use to customize its appearance.
| Property | Description |
|---|---|
| borderwidth | Frame border width |
| padding | Frame internal padding |
| fieldbackground | Text background color |
| foreground | Text font color |
| textpadding | Text external padding |
| insertwidth | Text cursor width |
| selectbackground | Text selection background color |
| selectforeground | Text selection font color |
For example, to set the border width to 1.5p:
from tkinter.ttk import Style
style = Style()
style.configure("ThemedText.TEntry", borderwidth="1.5p")Some third-party themes may not be fully compatible with TtkText. You can call the following function after setting the theme:
Sun Valley ttk theme
from tkinter import Tk
from tkinter.ttk import Style
import sv_ttk
def fix_sv_ttk(style: Style):
if sv_ttk.get_theme() == "light":
style.configure("ThemedText.TEntry", fieldbackground="#fdfdfd", textpadding=5)
style.map(
"ThemedText.TEntry",
fieldbackground=[
("hover", "!focus", "#f9f9f9"),
],
foreground=[
("pressed", style.lookup("TEntry", "foreground")),
]
)
else:
style.configure("ThemedText.TEntry", fieldbackground="#292929", textpadding=5)
style.map(
"ThemedText.TEntry",
fieldbackground=[
("hover", "!focus", "#2f2f2f"),
("focus", "#1c1c1c"),
],
foreground=[
("pressed", style.lookup("TEntry", "foreground")),
]
)
# Example
app = Tk()
sv_ttk.set_theme("light")
fix_sv_ttk(Style())
app.mainloop()Azure-ttk-theme
from tkinter import Tk
from tkinter.ttk import Style
def fix_azure_ttk(style: Style):
if style.theme_use() == "azure-light":
style.configure("ThemedText.TEntry", fieldbackground="#ffffff", textpadding=5)
else:
style.configure("ThemedText.TEntry", fieldbackground="#333333", textpadding=5)
# Example
app = Tk()
app.tk.call("source", "azure.tcl")
Style().theme_use("azure-light")
app.tk.call("set_theme", "light")
fix_azure_ttk(Style())
app.mainloop()Forest-ttk-theme
from tkinter import Tk
from tkinter.ttk import Style
def fix_forest_ttk(style: Style):
if style.theme_use() == "forest-light":
style.configure("ThemedText.TEntry", fieldbackground="#ffffff", textpadding=5, font="TkTextFont")
else:
style.configure("ThemedText.TEntry", fieldbackground="#313131", textpadding=5, font="TkTextFont")
# Example
app = Tk()
app.tk.call("source", "external-themes/forest-ttk-theme/forest-light.tcl")
Style().theme_use("forest-light")
fix_forest_ttk(Style())
app.mainloop()See CONTRIBUTING.md for details.
This project is licensed under the MIT License, see the LICENSE file for details.


