Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain in README.md how to integrate sv_ttk with 3rd party modules #143

Merged
merged 25 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,69 @@ root.mainloop()
```


## Tips and tricks
Our intention is to keep the `sv-ttk` package as simple as possible, while making it easy to integrate with other libraries.

<details>
<summary><b>Set the theme to the system theme</b></summary>

You can use [darkdetect](https://github.com/albertosottile/darkdetect) for that. Here's an example:

```python
import darkdetect

sv_ttk.set_theme(darkdetect.theme())
```

It's only a matter of an extra import and passing the result of `darkdetect.theme()` to ```sv_ttk.set_theme()`. It's that easy!
</details>


<details>
<summary><b>Dark Mode title bar on Windows</b></summary>

By default, sv_ttk doesn't change the title bar color on Windows when the theme is set to dark. But you can use [pywinstyles](https://github.com/Akascape/py-window-styles) to change the title bar color on Windows. Here's an example:

```python
import pywinstyles, sys

def apply_theme_to_titlebar(root):
version = sys.getwindowsversion()

if version.major == 10 and version.build >= 22000:
# Set the title bar color to the background color on Windows 11 for better appearance
if sv_ttk.get_theme() == "dark": pywinstyles.change_header_color(root, "#1c1c1c")
else: pywinstyles.change_header_color(root, "#fafafa")
elif version.major == 10:
if sv_ttk.get_theme() == "dark": pywinstyles.apply_style(root, "dark")
else: pywinstyles.apply_style(root, "normal")

# A hacky way to update the title bar's color on Windows 10 (it doesn't update instantly like on Windows 11)
root.wm_attributes("-alpha", 0.99)
root.wm_attributes("-alpha", 1)

# Example usage (replace `root` with the reference to your main/Toplevel window)
apply_theme_to_titlebar(root)
rdbende marked this conversation as resolved.
Show resolved Hide resolved
```

Note that on Windows 10, due to its limitations, you can only set the title bar's color to black for dark mode and white for light mode. On Windows 11 the title bar can be set to any color.

> [!WARNING]
> The ```apply_theme_to_titlebar``` function is meant to be called only on Windows.

Here's how the windows look after calling ```set_title_bar_color()```:

<p align="center">
<b>Windows 10</b>
<br>
<img src="assets/win10.png"/>
<br><br>
<b>Windows 11</b>
<br>
<img src="assets/win11.png"/>
</p>
</details>

rdbende marked this conversation as resolved.
Show resolved Hide resolved
## Wanna see more?
Check out my other ttk themes!
- The [Azure ttk theme](https://github.com/rdbende/Azure-ttk-theme)
Expand Down
Binary file added assets/win10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/win11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.