Skip to content

Commit ae504d1

Browse files
committed
feat(theme): improve Windows UI defaults and add theme guide
- Change Button use_ttk_buttons default behavior to True on Windows when omitted - Keep explicit use_ttk_buttons=True/False behavior unchanged - Keep Windows default theme as vista and document theme usage/customization - Add docs/theme.md and link it from docs/README.md - Add tests/theme/ttk_button.py example and lint docstring fix
1 parent e51f393 commit ae504d1

6 files changed

Lines changed: 131 additions & 4 deletions

File tree

TkEasyGUI/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ def set_default_theme() -> None:
259259
set_theme("aqua")
260260
elif is_win():
261261
# ('winnative', 'clam', 'alt', 'default', 'classic', 'vista', 'xpnative')
262-
# set_theme("winnative")
263-
# set_theme("default")
264262
set_theme("vista")
265263
else:
266264
set_theme("clam")

TkEasyGUI/widgets.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,14 +2371,15 @@ def __init__(
23712371
expand_y: bool = False,
23722372
pad: Optional[PadType] = None,
23732373
# other
2374-
use_ttk_buttons: bool = False,
2374+
use_ttk_buttons: Optional[bool] = None,
23752375
metadata: Optional[dict[str, Any]] = None,
23762376
**kw,
23772377
) -> None:
23782378
"""Create a Button element."""
23792379
key = button_text if (key is None) or (key == "") else key
23802380
super().__init__("Button", "TButton", key, False, metadata, **kw)
2381-
self.use_ttk = use_ttk_buttons # can select ttk or tk button
2381+
# On Windows, ttk buttons look more modern by default.
2382+
self.use_ttk = utils.is_win() if use_ttk_buttons is None else use_ttk_buttons
23822383
self.disabled = False
23832384
if disabled is not None:
23842385
self.props["disabled"] = self.disabled = disabled

TkEasyGUI/widgets_window.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def _create_root(self) -> tk.Tk:
5252
self._root.eval("tk::PlaceWindow . center")
5353
self._root.withdraw()
5454
if self._theme_name == "":
55+
# windows: winnative, clam, alt, default, classic, vista, xpnative
56+
# macOS: aqua, clam, alt, default, classic
5557
if _is_mac():
5658
self.set_theme("aqua")
5759
elif _is_win():

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Here is a list of elements:
6868
### TkEasyGUI Original features
6969

7070
- [Custom Events](https://github.com/kujirahand/tkeasygui-python/blob/main/docs/custom_events.md)
71+
- [Theme Guide](https://github.com/kujirahand/tkeasygui-python/blob/main/docs/theme.md)
7172

7273
### Package developper
7374

docs/theme.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# TkEasyGUI Theme Guide
2+
3+
This document explains how to use themes and how to change theme-related defaults in TkEasyGUI.
4+
5+
## Overview
6+
7+
TkEasyGUI uses `ttk` themes for modern widget rendering.
8+
You can switch themes at runtime using `set_theme()` or `theme()`.
9+
10+
Default theme by platform:
11+
12+
- macOS: `aqua`
13+
- Windows: `vista`
14+
- Linux/others: `clam`
15+
16+
## Basic theme usage
17+
18+
### Change theme with `set_theme`
19+
20+
```python
21+
import TkEasyGUI as eg
22+
23+
eg.set_theme("clam")
24+
window = eg.Window("Theme sample", [[eg.Button("OK", use_ttk_buttons=True)]])
25+
window.read()
26+
window.close()
27+
```
28+
29+
### Alias: `theme`
30+
31+
`theme()` is an alias of `set_theme()`.
32+
33+
```python
34+
import TkEasyGUI as eg
35+
36+
eg.theme("default")
37+
```
38+
39+
## List available themes
40+
41+
Use `get_tnemes()` to inspect themes available in your current Tk runtime.
42+
43+
```python
44+
import TkEasyGUI as eg
45+
46+
print(eg.get_tnemes())
47+
```
48+
49+
Note:
50+
- Function name is `get_tnemes()` in current API.
51+
52+
## Change button style behavior
53+
54+
`Button` can render with `ttk.Button` (modern) or `tk.Button` (classic).
55+
56+
- `use_ttk_buttons=True`: use `ttk.Button`
57+
- `use_ttk_buttons=False`: use `tk.Button`
58+
- `use_ttk_buttons=None` (default): Windows uses `ttk`, other OS keep previous default behavior
59+
60+
```python
61+
import TkEasyGUI as eg
62+
63+
layout = [
64+
[eg.Button("Modern", use_ttk_buttons=True)],
65+
[eg.Button("Classic", use_ttk_buttons=False)],
66+
]
67+
window = eg.Window("Buttons", layout)
68+
window.read()
69+
window.close()
70+
```
71+
72+
## How to customize defaults
73+
74+
### Global theme default
75+
76+
If you want to change the default theme for your app, call `set_theme()` before creating windows.
77+
78+
```python
79+
import TkEasyGUI as eg
80+
81+
eg.set_theme("winnative")
82+
```
83+
84+
### Revert to old Windows look
85+
86+
If you want behavior close to older Windows appearance:
87+
88+
```python
89+
import TkEasyGUI as eg
90+
91+
eg.set_theme("vista")
92+
layout = [[eg.Button("OK", use_ttk_buttons=False)]]
93+
window = eg.Window("Legacy look", layout)
94+
window.read()
95+
window.close()
96+
```
97+
98+
## Recommended test scripts
99+
100+
After changing theme defaults, validate with:
101+
102+
```bash
103+
python tests/file_viewer.py
104+
python tests/theme/ttk_button.py
105+
python tests/ui_test.py
106+
python tests/many_buttons.py
107+
```

tests/theme/ttk_button.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Compare ttk and classic button rendering."""
2+
3+
import TkEasyGUI as eg
4+
5+
layout = [
6+
[eg.Text("This is a modern button using ttk styles.")],
7+
[eg.Button("Modern", use_ttk_buttons=True)],
8+
[eg.HSeparator()],
9+
[eg.Text("This is a classic button using Tkinter styles.")],
10+
[eg.Button("Classic", use_ttk_buttons=False)],
11+
]
12+
window = eg.Window("Buttons", layout)
13+
for event, values in window.event_iter():
14+
if event == "Modern":
15+
eg.popup("You clicked the modern button!")
16+
if event == "Classic":
17+
eg.popup("You clicked the classic button!")
18+
window.close()

0 commit comments

Comments
 (0)