Next / Previous / Contents / Shipman's homepage

3. Using the FontSelect widget in your Tkinter application

If you are writing a Tkinter application and you want to let the user change one or more fonts, you can include a FontSelect widget in your application. Create it with this constructor:

w = FontSelect(master, font=f, listCount=L, observer=F)

The constructor returns a new, ungridded FontSelect widget.


The parent Frame widget in which this widget will be mastered.


If you don't like the font used inside this widget, supply this optional keyword argument with f set to your preferred font as a tkFont.Font object.


By default, the number of families displayed in the family Listbox is defined in Section 5.2.1, “LISTBOX_HEIGHT. If you want a different number, pass that number as an integer L to this optional keyword argument. This Listbox pretty much determines the overall height of the FontSelect widget on the screen.


An “observer” function to be called whenever any of the currently displayed font options change. The calling sequence is:


where newFont is a Python tkFont.Font object representing the currently selected font.

Here are the public attributes and methods of a FontSelect object:


A ScrollList widget containing the family names and associated scrollbar.


Returns the currently selected font as a Python tkFont.Font object. If no font has ever been set, returns None.


Returns a string describing all the current font options. This string starts with the family and size, followed optionally by the strings "bold" and/or "italic". Example: "luxi mono 14 bold italic". If no font has ever been set, returns None.


Adds an observer function f that will be called whenever any of the font options change. The calling sequence of the f function is as described under the observer=f argument to the FontSelect constructor.