The Font Selection Dialog allows a user to interactively select a font for use within your program. The dialog contains a FontSelection widget and xlsfonts). and buttons. An button is also available in the dialog but is initially hidden. The Font Selection Dialog allows a user to select a font from the available system fonts (the same ones that can be retrieved usingFigure 9.15, “Font Selection Dialog” illustrates the FontSelectionDialog display: The dialog contains a set of three notebook pages that provide:
The function to create a FontSelectionDialog is:
The title is a string that will be used to set the titlebar text. A Font Selection Dialog instance has several attributes:
The fontsel attribute provides a reference to the Font Selection widget. main_vbox is a reference to the gtk.VBox containing the fontsel and the action_area in the dialog. The action_area attribute is a reference to the gtk.HButtonBox that contains the , and buttons. The ok_button, cancel_button and apply_button attributes provide references to the , and buttons that can be used to set connections to the button signals. The apply_button reference can also be used to show() the button.You can set the initial font to be displayed in the fontseldlg by using the method:
The fontname argument is the name of a completely specified or partially specified system font. For example:
partially specifies the initial font. The font name of the currently selected font can be retrieved using the method:
The Font Selection Dialog has a Preview area that displays text using the currently selected font. The text that is used in the Preview area can be set with the method:
The preview text can be retrieved with the method:
The calendar.py example program uses a Font Selection Dialog to select the font to display the calendar information. Lines 105-110 define a callback that retrieves the font name from the Font Selection Dialog and uses it to set the font for the calendar widget. Lines 112-131 defines the method that creates the Font Selection Dialog, sets up the callbacks for the and buttons and displays the dialog. |