forked from j4321/tkFontChooser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.py
More file actions
45 lines (40 loc) · 1.36 KB
/
example_usage.py
File metadata and controls
45 lines (40 loc) · 1.36 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
from tkinter import Tk, ttk
from sys import platform
from tkfontselector.ask_font import ask_font
EXAMPLE_FONT_FAMILY = {
"family": "Comic Sans MS",
"size": 10,
"weight": "normal",
"slant": "roman",
"underline": 0,
"overstrike": 0,
}
if __name__ == "__main__":
"""Example Usage"""
root = Tk()
style = ttk.Style(root)
if "win" == platform[:3]:
style.theme_use("vista")
elif "darwin" in platform:
style.theme_use("clam")
else:
style.theme_use("clam")
bg = style.lookup("TLabel", "background")
root.configure(bg=bg)
label = ttk.Label(root, text="Chosen font: ")
label.pack(padx=10, pady=(10, 4))
def callback():
font = ask_font(root, title="Choose a font", font_args=EXAMPLE_FONT_FAMILY)
if font:
# spaces in the family name need to be escaped
font["family"] = font["family"].replace(" ", "\ ")
font_str = "%(family)s %(size)i %(weight)s %(slant)s" % font
if font["underline"]:
font_str += " underline"
if font["overstrike"]:
font_str += " overstrike"
label.configure(
font=font_str, text="Chosen font: " + font_str.replace("\ ", " ")
)
ttk.Button(root, text="Font Selector", command=callback).pack(padx=10, pady=(4, 10))
root.mainloop()