Hello, World! Simple Widgets Binding Events More Widgets Scrollbars Menus Canvas Make things look Beautiful More Information

We are moving to this wiki

Making Things look Beautiful

Default Tk looks may not be to your liking (it is one of the perceived disadvantages of Tk w.r.t. gtk and Qt). So let's polish this toolkit up a bit.

Fonts

This is the font used by emacs:
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

Kero