| FontListBox |
UserPreferences |
| Tkinter Wiki | FrontPage | RecentChanges | TitleIndex | WordIndex | SiteNavigation | HelpContents | moin.sf.net |
KevinWalzer: I've had a hard time figuring out how to display the available fonts on my system in a Tkinter application. Finally, after a lot of time on Google codesearch and also rummaging around in Tkinter sample code (such as idlelib), I came up with this code snippet. I hope others find it useful. Variations (such as getting the font list to display correctly in an optionmenu) would also be welcomed.
from Tkinter import *
import tkFont
root = Tk()
fonts=list(tkFont.families())
fonts.sort()
display = Listbox(root)
display.pack(fill=BOTH, expand=YES, side=LEFT)
scroll = Scrollbar(root)
scroll.pack(side=RIGHT, fill=Y, expand=NO)
scroll.configure(command=display.yview)
display.configure(yscrollcommand=scroll.set)
for item in fonts:
display.insert(END, item)
root.mainloop()
Screenshot: