This repository was archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun_sample.py
More file actions
201 lines (143 loc) · 4.96 KB
/
Copy pathrun_sample.py
File metadata and controls
201 lines (143 loc) · 4.96 KB
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
import tkinter as tk
from PIL import Image, ImageTk, ImageDraw
from pytkfaicons import REFTAG
from pytkfaicons import get_meta
from pytkfaicons.fonts import get_font, get_font_icon
root = tk.Tk()
frame_t = tk.Frame(root)
# info text
frame_m = tk.Frame(root)
tk.Label(frame_m, text=f"fontawesome - {REFTAG}").pack(side="top", pady=10)
tk.Label(frame_m, text="font based - different size and color support").pack(
side="top", pady=10
)
frame_m.pack()
# use fonts
f_brands = get_font("brands", 44)
print(f_brands.getname())
f_solid = get_font("solid", 44)
print(f_solid.getname())
f_regular = get_font("regular", 44)
print(f_regular.getname())
# custom image - thats how get_font_icon() is implemented
meta_ic = get_meta("asterisk")
unicode_ic = meta_ic["unicode"] # this is a hex string
style_ic = meta_ic["styles"] # list of supported fonts
print("icon-data", unicode_ic, style_ic)
print("icon-meta", meta_ic)
# convert hex string to unicode
unicode_text = chr(int(unicode_ic, 16))
# load the first supported font
font_ic = get_font(style_ic[0], 44)
# background color == green
imag = Image.new(mode="RGB", size=(66, 66), color="black")
draw = ImageDraw.Draw(im=imag)
# draw text with color == white
draw.text(xy=(33, 33), text=unicode_text, font=font_ic, fill="white", anchor="mm")
im = ImageTk.PhotoImage(imag)
# end-of custom image
frame2 = tk.Frame(root)
img0 = get_font_icon("arrow-left", style="solid", height=64, fg="green")
tk.Button(frame2, justify=tk.LEFT, padx=10, image=img0).pack(side="left")
img1 = get_font_icon("arrow-right", style="solid", height=48, fg="green", bg="black")
tk.Button(frame2, justify=tk.LEFT, padx=10, image=img1).pack(side="left")
img2 = get_font_icon("asterisk", style="solid", height=32, fg="blue", bg="black")
tk.Button(frame2, justify=tk.LEFT, padx=10, image=img2).pack(side="left")
img3 = get_font_icon("barcode", style="solid", height=24, fg="blue")
tk.Button(frame2, justify=tk.LEFT, padx=10, image=img3).pack(side="left")
img4 = get_font_icon("baby", style="solid", height=12)
tk.Button(frame2, justify=tk.LEFT, padx=10, image=img4).pack(side="left")
img5 = get_font_icon("bahai", style="solid", height=8)
tk.Button(frame2, justify=tk.LEFT, padx=10, image=img5).pack(side="left")
img6 = get_font_icon("bars", style="solid", height=6)
tk.Button(frame2, justify=tk.LEFT, padx=10, image=img6).pack(side="left")
frame2.pack()
frame3 = tk.Frame(root)
# use the custom image
tk.Button(frame3, justify=tk.LEFT, padx=10, image=im).pack(side="left")
im_python = get_font_icon("python", height=100, bg="green", fg="white")
tk.Button(frame3, justify=tk.LEFT, padx=10, image=im_python).pack(side="left")
im_baby = get_font_icon("baby", height=44, bg="blue", fg="white")
tk.Button(frame3, justify=tk.LEFT, padx=10, image=im_baby).pack(side="left")
im_bahai = get_font_icon("bahai", height=44, image_size=(100, 70), bg="red", fg="white")
tk.Button(frame3, justify=tk.LEFT, padx=10, image=im_bahai).pack(side="left")
frame3.pack()
frame4 = tk.Frame(root)
tk.Label(frame4, text="font styles").pack(side="left")
QUEST = "question-circle"
im_quest = get_font_icon(
QUEST,
style="regular",
height=22,
image_size=(50, 50),
bg="black",
fg="white",
)
tk.Button(frame4, justify=tk.LEFT, padx=10, image=im_quest).pack(side="left")
im_quest2 = get_font_icon(
QUEST,
style="solid",
height=22,
image_size=(50, 50),
bg="black",
fg="white",
)
tk.Button(frame4, justify=tk.LEFT, padx=10, image=im_quest2).pack(side="left")
im_quest3 = get_font_icon(
QUEST,
style="regular",
height=22,
image_size=(50, 50),
)
tk.Button(frame4, justify=tk.LEFT, padx=10, image=im_quest3).pack(side="left")
im_quest4 = get_font_icon(
QUEST,
style="solid",
height=22,
image_size=(50, 50),
)
tk.Button(frame4, justify=tk.LEFT, padx=10, image=im_quest4).pack(side="left")
frame4.pack()
frame5 = tk.Frame(root)
tk.Label(frame5, text="coding icons").pack(side="left", pady=20)
frame5.pack()
frame6 = tk.Frame(root)
im_code = get_font_icon(
"code",
height=22,
image_size=(33, 33),
)
tk.Button(frame6, justify=tk.LEFT, padx=10, image=im_code).pack(side="left")
im_code2 = get_font_icon(
"bug",
height=22,
image_size=(33, 33),
)
tk.Button(frame6, justify=tk.LEFT, padx=10, image=im_code2).pack(side="left")
im_code_branch = get_font_icon(
"code-branch",
height=22,
image_size=(33, 33),
)
tk.Button(frame6, justify=tk.LEFT, padx=10, image=im_code_branch).pack(side="left")
im_code_cmp = get_font_icon(
"cube",
height=22,
image_size=(33, 33),
)
tk.Button(frame6, justify=tk.LEFT, padx=10, image=im_code_cmp).pack(side="left")
im_git_alt = get_font_icon(
"git-alt",
height=22,
image_size=(33, 33),
)
tk.Button(frame6, justify=tk.LEFT, padx=10, image=im_git_alt).pack(side="left")
im_git_hub = get_font_icon(
"github",
height=22,
image_size=(33, 33),
)
tk.Button(frame6, justify=tk.LEFT, padx=10, image=im_git_hub).pack(side="left")
frame6.pack()
# run tkinter mainloop
root.mainloop()