how to show installed tkinter fonts

Solutions on MaxInterview for how to show installed tkinter fonts by the best coders in the world

showing results for - "how to show installed tkinter fonts"
Chiara
22 Jun 2020
1from tkinter import *
2from tkinter import font
3
4root = Tk()
5root.title('Font Families')
6fonts=list(font.families())
7fonts.sort()
8
9def populate(frame):
10    '''Put in the fonts'''
11    listnumber = 1
12    for item in fonts:
13        label = "listlabel" + str(listnumber)
14        label = Label(frame,text=item,font=(item, 16)).pack()
15        listnumber += 1
16
17def onFrameConfigure(canvas):
18    '''Reset the scroll region to encompass the inner frame'''
19    canvas.configure(scrollregion=canvas.bbox("all"))
20
21canvas = Canvas(root, borderwidth=0, background="#ffffff")
22frame = Frame(canvas, background="#ffffff")
23vsb = Scrollbar(root, orient="vertical", command=canvas.yview)
24canvas.configure(yscrollcommand=vsb.set)
25
26vsb.pack(side="right", fill="y")
27canvas.pack(side="left", fill="both", expand=True)
28canvas.create_window((4,4), window=frame, anchor="nw")
29
30frame.bind("<Configure>", lambda event, canvas=canvas: onFrameConfigure(canvas))
31
32populate(frame)
33
34root.mainloop()
35