# Fonts in R TclTk

The following example illustrates how to specify the font to be used in Tk windows/widgets. If you explicitly add the option font = myFont to every widget you create (where possible), then you only have to change myFont in one place, if for example you wish to use a bigger font for a presentation with a projector. You may wish to define a few different fonts - one fixed width font, one font for headings, etc.

library(tcltk2)

win1 <- tktoplevel()

fontHeading <- tkfont.create(family = "Arial", size = 24,
weight = "bold", slant = "italic")
fontTextLabel <- tkfont.create(family = "Times New Roman", size = 12)
fontFixedWidth <- tkfont.create(family = "Courier New", size = 12)

tkgrid(tk2label(win1, text = "A Nice Big Font for the Heading",
tkgrid(tk2label(win1, text = "A normal text label.",
tkgrid(tk2label(win1, text = "A fixed width font.",
font = fontFixedWidth, background = "white"), padx = 10, pady = c(5, 15))

### Font selector

The tcltk2 package proposes a font-selector dialog box:

fontHeading2 <- tk2chooseFont(font = fontHeading)
tkgrid(tk2label(win1, text = "A heading with the new font",
font = fontHeading2), padx = 10, pady = 15)

Select a different font, then…

… click OK.