| Hello, World! | Simple Widgets | Binding Events | More Widgets | Scrollbars | Menus | Canvas | Make things look Beautiful | More Information |
| We are moving to this wiki |
|---|
editor = TkText.new() { width 80 }.pack
editor.font('9x15')
If you use a font that is not installed, Tk falls back to fixed.
Another way of handling fonts is explicitly using a TkFont:
font = TkFont.new('courier')
font.configure('size'=>36) # huuuge
editor.font(font)
The obvious advantage is that you can manipulate the font (check the Tk manual
for details; you'll want to know {'weight'=>'bold',
'slant'=>'italic'}). But you can also use this font for multiple widgets,
whereas the previous method would create a separate font for each widget
(consuming quite some startup time as well; try a few hundreds of TkEntry's for
a spreadsheet).
To list some font families, use
TkFont.families()where is the rest? like '9x15'?
As tempting as it may be to use something really nice here, there are likely cases where you want to stick with a non-proportional font. These are input-widgets TkEntry and TkText. A fixed-width font reads better, because points and other tiny characters don't get obscured. When limited to 80 characters in width, you can print the resulting code on all conceivable printers (i.e. TkText.new(nil, 'width'=>80)).
| Hello, World! | Simple Widgets | Binding Events | More Widgets | Scrollbars | Menus | Canvas | Make things look Beautiful | More Information |