-
Notifications
You must be signed in to change notification settings - Fork 0
/
TkFonts.py
46 lines (33 loc) · 1.2 KB
/
TkFonts.py
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
from tkinter import *
from tkinter import font
root = Tk()
root.title('Font Families')
fonts = list(font.families())
print(fonts)
fonts.sort()
def populate(frame):
'''Put in the fonts'''
listnumber = 1
for i, item in enumerate(fonts):
label = "listlabel" + str(listnumber)
label = Label(frame, text=item, font=(item, 16))
label.grid(row=i)
label.bind("<Button-1>", lambda e, item=item: copy_to_clipboard(item))
listnumber += 1
def copy_to_clipboard(item):
root.clipboard_clear()
root.clipboard_append("font=('" + item.lstrip('@') + "', 12)")
def onFrameConfigure(canvas):
'''Reset the scroll region to encompass the inner frame'''
canvas.configure(scrollregion=canvas.bbox("all"))
canvas = Canvas(root, borderwidth=0, background="#ffffff")
frame = Frame(canvas, background="#ffffff")
vsb = Scrollbar(root, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand=vsb.set)
vsb.pack(side="right", fill="y")
canvas.pack(side="left", fill="both", expand=True)
canvas.create_window((4, 4), window=frame, anchor="nw")
frame.bind("<Configure>",
lambda event, canvas=canvas: onFrameConfigure(canvas))
populate(frame)
root.mainloop()