1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
"""This demonstrates good part of the syntax accepted by theme_create.
This is a translation of plastik.tcl to python.
You will need the images used by the plastik theme to test this. The
images (and other tile themes) can be retrived by doing:
$ cvs -z3 -d:pserver:anonymous@tktable.cvs.sourceforge.net:/cvsroot/tktable \
co tile-themes
To test this module you should do, for example:
import Tkinter
import plastik_theme
root = Tkinter.Tk()
plastik_theme.install(plastik_image_dir)
...
Where plastik_image_dir contains the path to the images directory used by
the plastik theme, something like: tile-themes/plastik/plastik
"""
import os
import glob
from tkinter import ttk, PhotoImage
__all__ = ['install']
colors = {
"frame": "#efefef",
"disabledfg": "#aaaaaa",
"selectbg": "#657a9e",
"selectfg": "#ffffff"
}
imgs = {}
def _load_imgs(imgdir):
imgdir = os.path.expanduser(imgdir)
if not os.path.isdir(imgdir):
raise Exception("%r is not a directory, can't load images" % imgdir)
for f in glob.glob("%s/*.gif" % imgdir):
img = os.path.split(f)[1]
name = img[:-4]
imgs[name] = PhotoImage(name, file=f, format="gif89")
def install(imgdir):
_load_imgs(imgdir)
style = ttk.Style()
style.theme_create("plastik", "default", settings={
".": {
"configure":
{"background": colors['frame'],
"troughcolor": colors['frame'],
"selectbackground": colors['selectbg'],
"selectforeground": colors['selectfg'],
"fieldbackground": colors['frame'],
"font": "TkDefaultFont",
"borderwidth": 1},
"map": {"foreground": [("disabled", colors['disabledfg'])]}
},
"Vertical.TScrollbar": {"layout": [
("Vertical.Scrollbar.uparrow", {"side": "top", "sticky": ''}),
("Vertical.Scrollbar.downarrow", {"side": "bottom", "sticky": ''}),
("Vertical.Scrollbar.uparrow", {"side": "bottom", "sticky": ''}),
("Vertical.Scrollbar.trough", {"sticky": "ns", "children":
[("Vertical.Scrollbar.thumb", {"expand": 1, "unit": 1,
"children": [("Vertical.Scrollbar.grip", {"sticky": ''})]
})]
})]
},
"Horizontal.TScrollbar": {"layout": [
("Horizontal.Scrollbar.leftarrow", {"side": "left", "sticky": ''}),
("Horizontal.Scrollbar.rightarrow",
{"side": "right", "sticky": ''}),
("Horizontal.Scrollbar.leftarrow",
{"side": "right", "sticky": ''}),
("Horizontal.Scrollbar.trough", {"sticky": "ew", "children":
[("Horizontal.Scrollbar.thumb", {"expand": 1, "unit": 1,
"children": [("Horizontal.Scrollbar.grip", {"sticky": ''})]
})]
})]
},
"TButton": {
"configure": {"width": 10, "anchor": "center"},
"layout": [
("Button.button", {"children":
[("Button.focus", {"children":
[("Button.padding", {"children":
[("Button.label", {"side": "left", "expand": 1})]
})]
})]
})
]
},
"Toolbutton": {
"configure": {"anchor": "center"},
"layout": [
("Toolbutton.border", {"children":
[("Toolbutton.button", {"children":
[("Toolbutton.padding", {"children":
[("Toolbutton.label", {"side":"left", "expand":1})]
})]
})]
})
]
},
"TMenubutton": {"layout": [
("Menubutton.button", {"children":
[("Menubutton.indicator", {"side": "right"}),
("Menubutton.focus", {"children":
[("Menubutton.padding", {"children":
[("Menubutton.label", {"side": "left", "expand": 1})]
})]
})]
})]
},
"TNotebook": {"configure": {"tabmargins": [0, 2, 0, 0]}},
"TNotebook.tab": {
"configure": {"padding": [6, 2, 6, 2], "expand": [0, 0, 2]},
"map": {"expand": [("selected", [1, 2, 4, 2])]}
},
"Treeview": {"configure": {"padding": 0}},
# elements
"Button.button": {"element create":
("image", 'button-n',
("pressed", 'button-p'), ("active", 'button-h'),
{"border": [4, 10], "padding": 4, "sticky":"ewns"}
)
},
"Toolbutton.button": {"element create":
("image", 'tbutton-n',
("selected", 'tbutton-p'), ("pressed", 'tbutton-p'),
("active", 'tbutton-h'),
{"border": [4, 9], "padding": 3, "sticky": "news"}
)
},
"Checkbutton.indicator": {"element create":
("image", 'check-nu',
('active', 'selected', 'check-hc'),
('pressed', 'selected', 'check-pc'),
('active', 'check-hu'),
("selected", 'check-nc'),
{"sticky": ''}
)
},
"Radiobutton.indicator": {"element create":
("image", 'radio-nu',
('active', 'selected', 'radio-hc'),
('pressed', 'selected', 'radio-pc'),
('active', 'radio-hu'), ('selected', 'radio-nc'),
{"sticky": ''}
)
},
"Horizontal.Scrollbar.thumb": {"element create":
("image", 'hsb-n', {"border": 3, "sticky": "ew"})
},
"Horizontal.Scrollbar.grip": {"element create": ("image", 'hsb-g')},
"Horizontal.Scrollbar.trough": {"element create": ("image", 'hsb-t')},
"Vertical.Scrollbar.thumb": {"element create":
("image", 'vsb-n', {"border": 3, "sticky": "ns"})
},
"Vertical.Scrollbar.grip": {"element create": ("image", 'vsb-g')},
"Vertical.Scrollbar.trough": {"element create": ("image", 'vsb-t')},
"Scrollbar.uparrow": {"element create":
("image", 'arrowup-n', ("pressed", 'arrowup-p'), {"sticky": ''})
},
"Scrollbar.downarrow": {"element create":
("image", 'arrowdown-n',
("pressed", 'arrowdown-p'), {'sticky': ''})
},
"Scrollbar.leftarrow": {"element create":
("image", 'arrowleft-n',
("pressed", 'arrowleft-p'), {'sticky': ''})
},
"Scrollbar.rightarrow": {"element create":
("image", 'arrowright-n', ("pressed", 'arrowright-p'),
{'sticky': ''})
},
"Horizontal.Scale.slider": {"element create":
("image", 'hslider-n', {'sticky': ''})
},
"Horizontal.Scale.trough": {"element create":
("image", 'hslider-t', {'border': 1, 'padding': 0})
},
"Vertical.Scale.slider": {"element create":
("image", 'vslider-n', {'sticky': ''})
},
"Vertical.Scale.trough": {"element create":
("image", 'vslider-t', {'border': 1, 'padding': 0})
},
"Entry.field": {"element create":
("image", 'entry-n',
("focus", 'entry-f'),
{'border': 2, 'padding': [3, 4], 'sticky': 'news'}
)
},
"Labelframe.border": {"element create":
("image", 'border', {'border': 4, 'padding': 4, 'sticky': 'news'})
},
"Menubutton.button": {"element create":
("image", 'combo-r',
('active', 'combo-ra'),
{'sticky': 'news', 'border': [4, 6, 24, 15],
'padding': [4, 4, 5]}
)
},
"Menubutton.indicator": {"element create":
("image", 'arrow-d', {"sticky": "e", "border": [15, 0, 0, 0]})
},
"Combobox.field": {"element create":
("image", 'combo-n',
('readonly', 'active', 'combo-ra'),
('focus', 'active', 'combo-fa'),
('active', 'combo-a'), ('!readonly', 'focus', 'combo-f'),
('readonly', 'combo-r'),
{'border': [4, 6, 24, 15], 'padding': [4, 4, 5],
'sticky': 'news'}
)
},
"Combobox.downarrow": {"element create":
("image", 'arrow-d', {'sticky': 'e', 'border': [15, 0, 0, 0]})
},
"Notebook.client": {"element create":
("image", 'notebook-c', {'border': 4})
},
"Notebook.tab": {"element create":
("image", 'notebook-tn',
("selected", 'notebook-ts'), ("active", 'notebook-ta'),
{'padding': [0, 2, 0, 0], 'border': [4, 10, 4, 10]}
)
},
"Progressbar.trough": {"element create":
("image", 'hprogress-t', {'border': 2})
},
"Horizontal.Progressbar.pbar": {"element create":
("image", 'hprogress-b', {'border': [2, 9]})
},
"Vertical.Progressbar.pbar": {"element create":
("image", 'vprogress-b', {'border': [9, 2]})
},
"Treeheading.cell": {"element create":
("image", 'tree-n',
("pressed", 'tree-p'),
{'border': [4, 10], 'padding': 4, 'sticky': 'news'}
)
}
})
style.theme_use("plastik")
|