Skip to content

Commit cebd821

Browse files
committed
Continue working on Python project
1 parent 479e423 commit cebd821

File tree

3 files changed

+126
-10
lines changed

3 files changed

+126
-10
lines changed

example.py

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,76 @@
1-
import tkinter as tk
2-
from tkinter import ttk
1+
"""
2+
Author: RedFantom
3+
License: GNU GPLv3
4+
Copyright (c) 2018 RedFantom
5+
"""
6+
import os
7+
import sys
8+
if sys.version_info.major == 3:
9+
import tkinter as tk
10+
from tkinter import ttk
11+
else:
12+
import Tkinter as tk
13+
import ttk
314

4-
window = tk.Tk()
5-
style = ttk.Style(window)
6-
window.eval("set dir /usr/lib/tcltk/gtkTtk0.5; source /usr/lib/tcltk/gtkTtk0.5/pkgIndex.tcl")
7-
window.tk.call("package", "require", "ttk::theme::gtkTtk");
8-
print(style.theme_names())
915

10-
style.theme_use("gtkTtk")
11-
ttk.Button(window, text="Destroy", command=window.destroy).pack()
16+
class Example(tk.Tk):
17+
"""
18+
Example that is used to create screenshots for new themes.
19+
"""
20+
def __init__(self):
21+
tk.Tk.__init__(self)
22+
# Create widgets
23+
self.menu = tk.Menu(self, tearoff=False)
24+
self.sub_menu = tk.Menu(self.menu, tearoff=False)
25+
self.sub_menu.add_command(label="Exit", command=self.destroy)
26+
self.menu.add_cascade(menu=self.sub_menu, label="General")
27+
self.config(menu=self.menu)
28+
self.label = ttk.Label(self, text="This is an example label.")
29+
self.dropdown = ttk.OptionMenu(self, tk.StringVar(), "First value", "Second Value")
30+
self.entry = ttk.Entry(self, textvariable=tk.StringVar(value="Default entry value."))
31+
self.button = ttk.Button(self, text="Button")
32+
self.radio_one = ttk.Radiobutton(self, text="Radio one", value=True)
33+
self.radio_two = ttk.Radiobutton(self, text="Radio two", value=False)
34+
self.scroll = ttk.Scrollbar(self, orient=tk.VERTICAL)
35+
self.checked = ttk.Checkbutton(self, text="Checked", variable=tk.BooleanVar(value=True))
36+
self.unchecked = ttk.Checkbutton(self, text="Unchecked")
37+
self.tree = ttk.Treeview(self, height=4, show=("tree", "headings"))
38+
self.setup_tree()
39+
self.progress = ttk.Progressbar(self, maximum=100, value=50)
40+
# Grid widgets
41+
self.grid_widgets()
1242

13-
window.mainloop()
43+
def setup_tree(self):
44+
"""Setup an example Treeview"""
45+
self.tree.insert("", tk.END, text="Example 1", iid="1")
46+
self.tree.insert("", tk.END, text="Example 2", iid="2")
47+
self.tree.insert("2", tk.END, text="Example Child")
48+
self.tree.heading("#0", text="Example heading")
49+
50+
def grid_widgets(self):
51+
"""Put widgets in the grid"""
52+
sticky = {"sticky": "nswe"}
53+
self.label.grid(row=1, column=1, columnspan=2, **sticky)
54+
self.dropdown.grid(row=2, column=1, **sticky)
55+
self.entry.grid(row=2, column=2, **sticky)
56+
self.button.grid(row=3, column=1, columnspan=2, **sticky)
57+
self.radio_one.grid(row=4, column=1, **sticky)
58+
self.radio_two.grid(row=4, column=2, **sticky)
59+
self.checked.grid(row=5, column=1, **sticky)
60+
self.unchecked.grid(row=5, column=2, **sticky)
61+
self.scroll.grid(row=1, column=3, rowspan=8, padx=5, **sticky)
62+
self.tree.grid(row=6, column=1, columnspan=2, **sticky)
63+
self.progress.grid(row=9, column=1, columnspan=2, padx=5, pady=5, **sticky)
64+
65+
66+
if __name__ == '__main__':
67+
window = Example()
68+
style = ttk.Style(window)
69+
window.eval("set dir /usr/lib/tcltk/tcl8.6/gtkTtk0.5; source /usr/lib/tcltk/tcl8.6/gtkTtk0.5/pkgIndex.tcl")
70+
window.tk.call("package", "require", "ttk::theme::gtkTtk")
71+
print(style.theme_names())
72+
73+
style.theme_use("gtkTtk")
74+
75+
window.mainloop()
1476

setup.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
Author: RedFantom
3+
License: GNU GPLv3
4+
Copyright (c) 2020 RedFantom
5+
"""
6+
try:
7+
from skbuild import setup
8+
from skbuild.command.build import build
9+
except ImportError:
10+
print("scikit-build is required to build this project")
11+
print("install with `python -m pip install scikit-build`")
12+
raise
13+
import glob
14+
from shutil import copyfile
15+
import os
16+
17+
18+
def read(file_name):
19+
with open(file_name) as fi:
20+
contents = fi.read()
21+
return contents
22+
23+
24+
class BuildCommand(build):
25+
"""
26+
Intercept the build command to build the required modules in ./build
27+
28+
gttk depends on a library built from source. Building this library
29+
requires the following to be installed, Ubuntu package names:
30+
- libx11-dev
31+
- libgtk2.0-dev
32+
- libgdk-pixbuf2.0-dev
33+
- tcl-dev
34+
- tk-dev
35+
"""
36+
37+
def run(self):
38+
build.run(self)
39+
40+
41+
setup(
42+
name="gttk",
43+
version="0.1.0",
44+
packages=["gttk"],
45+
description="GTK theme for Tkinter/ttk",
46+
author="The gttk/tile-gtk/gtkTtk authors",
47+
url="https://github.com/RedFantom/python-gttk",
48+
download_url="https://github.com/RedFantom/python-gttk/releases",
49+
license="GNU GPLv3",
50+
long_description=read("README.md"),
51+
zip_safe=False,
52+
install_requires=["scikit-build"],
53+
cmdclass={"build": BuildCommand}
54+
)

tests/test_widgets.py

Whitespace-only changes.

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