Skip to content

Commit 0496909

Browse files
committed
Update README.md and add screenshots
1 parent 13c3eaa commit 0496909

File tree

4 files changed

+114
-3
lines changed

4 files changed

+114
-3
lines changed

README.md

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,91 @@
1-
# python-gttk: Gtk Themeing for Tkinter/ttk
2-
![](https://api.travis-ci.com/RedFantom/python-gttk.svg?branch=master)
1+
# GTK Theme for Python's tkinter/ttk
2+
![Build Status](https://api.travis-ci.com/RedFantom/python-gttk.svg?branch=master)
3+
4+
Would you like to have a more native look for your Tkinter application?
5+
Are the themes provided in [ttkthemes](https://github.com/TkinterEP/ttkthemes)
6+
not to your liking?
7+
8+
This package provides a version of [`gtkTtk`](https://github.com/Geballin/gtkTtk),
9+
formerly [`tilegtk`](https://github.com/xiaq/tile-gtk) packaged for
10+
usage with Python. Simply follow the installation instructions and all
11+
required files are installed to the site package directory.
12+
13+
## Installation
14+
These instructions are for Ubuntu, Python 3.5 or higher. Any lower
15+
version may work, but is not supported. On other distributions, package
16+
names may be different.
17+
```bash
18+
# Build Tools
19+
sudo apt install build-essential cmake
20+
# Required Libraries
21+
sudo apt install libgtk2.0-dev libglib2.0-dev tcl-dev tk-dev
22+
# Required Python packages
23+
python -m pip install scikit-build
24+
25+
python setup.py install
26+
```
27+
28+
## Usage
29+
Simply import the package, and the theme is loaded automatically.
30+
```python
31+
import tkinter as tk
32+
from tkinter import ttk
33+
import gttk
34+
35+
window = tk.Tk()
36+
style = ttk.Style()
37+
style.theme_use("gttk")
38+
ttk.Button(window, text="Destroy", command=window.destroy).pack()
39+
40+
window.mainloop()
41+
```
42+
43+
If you encounter an error because you are running in the repository,
44+
directory, make sure to disallow imports from the working directory
45+
before importing `gttk`:
46+
```python
47+
import sys
48+
sys.path = sys.path[2:]
49+
import gttk
50+
```
51+
52+
## Screenshots
53+
`gttk` should work with any GTK theme you can throw at it, but below
54+
are the themes Yaru and Adwaita as examples.
55+
56+
![Yaru Example](https://raw.githubusercontent.com/RedFantom/python-gttk/master/screenshots/yaru.png)
57+
![Adapta Example](https://raw.githubusercontent.com/RedFantom/python-gttk/master/screenshots/adwaita.png)
58+
59+
## License and Copyright
60+
This repository provides a wrapper around `gttk`, which is a renamed
61+
version of `gtkTtk`, which in turn is a renamed version of `tile-gtk`.
62+
The original `tile-gtk` is available under hte MIT License. This version
63+
is available only under GNU GPLv3.
64+
65+
```
66+
python-gttk
67+
Copyright (c) 2008-2012 Georgios Petasis
68+
Copyright (c) 2012 Cheer Xiao
69+
Copyright (c) 2019-2020 Geballin
70+
Copyright (c) 2020 RedFantom
71+
72+
This program is free software: you can redistribute it and/or modify
73+
it under the terms of the GNU General Public License as published by
74+
the Free Software Foundation, either version 3 of the License, or
75+
(at your option) any later version.
76+
77+
This program is distributed in the hope that it will be useful,
78+
but WITHOUT ANY WARRANTY; without even the implied warranty of
79+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80+
GNU General Public License for more details.
81+
82+
You should have received a copy of the GNU General Public License
83+
along with this program. If not, see <http://www.gnu.org/licenses/>.
84+
```
85+
86+
## Project State
87+
`tile-gtk`, `gtkTtk` and hence also `gttk` are far from perfect. You may
88+
encounter various graphical artifacts when using particular themes,
89+
while others work without flaws.
90+
91+
You are welcome to report any issues, and pull requests are even better.

example.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""
22
Author: RedFantom
33
License: GNU GPLv3
4-
Copyright (c) 2018 RedFantom
4+
Copyright (c) 2018-2020 RedFantom
55
"""
6+
import os
67
import sys
78
import tkinter as tk
89
from tkinter import ttk
@@ -30,6 +31,7 @@ def __init__(self):
3031
self.tree = ttk.Treeview(self, height=4, show=("tree", "headings"))
3132
self.setup_tree()
3233
self.progress = ttk.Progressbar(self, maximum=100, value=50)
34+
self.bind("<F10>", self.screenshot)
3335
# Grid widgets
3436
self.grid_widgets()
3537

@@ -55,6 +57,26 @@ def grid_widgets(self):
5557
self.tree.grid(row=6, column=1, columnspan=2, **sticky)
5658
self.progress.grid(row=9, column=1, columnspan=2, padx=5, pady=5, **sticky)
5759

60+
def screenshot(self, *args):
61+
"""Take a screenshot, crop and save"""
62+
try:
63+
from PIL import Image
64+
from mss import mss
65+
except ImportError:
66+
print("Taking a screenshot requires additional packages: 'pillow' and 'mss'")
67+
raise
68+
if not os.path.exists("screenshots"):
69+
os.makedirs("screenshots")
70+
box = {
71+
"top": self.winfo_y(),
72+
"left": self.winfo_x(),
73+
"width": self.winfo_width(),
74+
"height": self.winfo_height()
75+
}
76+
screenshot = mss().grab(box)
77+
screenshot = Image.frombytes("RGB", screenshot.size, screenshot.rgb)
78+
screenshot.save("screenshots/{}.png".format(ttk.Style(self).theme_use()))
79+
5880

5981
if __name__ == '__main__':
6082
sys.path = sys.path[2:]

screenshots/adwaita.png

10.3 KB
Loading

screenshots/yaru.png

9.81 KB
Loading

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy