Hello,
I already posted this question to the ruby-core mailing-list, but as I
received no answer, I suppose that it was not the right place 
I would like to get the size of a TkFont.
It could be done with something like …
require ‘tk’
font = TkFont.new…
…
size = font.configure :size
… as it is descibed in the Tk documentation (configure with an
attribute without a value get the value of this attribute).
Unfortunately, this code returns the font object instead of the size
attribute.
It is confirmed in the configure_core_tk8x method in
ext/tk/lib/tk/font.rb file (line 1328) :
def configure_core_tk8x(font, slot, value=None)
…
self
end
So my question : is it a bug or there is another (specific ruby) way to
get the font attributes ?
Thanks and regards,
Lionel Maiaux
Try
require 'tk'
font = TkFont.new
size = font.size #=> 12 (on my system)
Regards, Morton
From: Lionel MAIAUX [email protected]
Subject: Incorrect return of the TkFont configure instance method when
no value
Date: Thu, 31 Aug 2006 17:09:14 +0900
Message-ID: [email protected]
I would like to get the size of a TkFont.
It could be done with something like …
require ‘tk’
font = TkFont.new…
…
size = font.configure :size
… as it is descibed in the Tk documentation (configure with an
attribute without a value get the value of this attribute).
On Ruby/Tk, you can use ‘configure’ methods only to set attibutes.
When you want the attibute value of the font,
please use one of the followings.
font.configinfo(:size) or font.configinfo(‘size’)
font[:size] or font[‘size’]
font.size
And when you want to set a value,
font.configure(:size, value) or font.configure(‘size’, value) # pair
font.configure(:size=>value) or font.configure(‘size’=>value) # Hash
font[:size] = value or font[‘size’] = value
font.size(value) or font.size = value
So, for example, you can control the buttons’ font size
by something like as the following. 
b1 = TkButton.new(:text=>‘FOO’).pack
f = b1.font
b2 = TkButton.new(:text=>‘BAR’, :font=>f).pack
lbl = TkButton.new(:text=>‘Label’, :font=>f).pack
p f.size # e.g. fontsize == 9
f.size -= 3 # fontsize == 6 on the label and both buttons
f.size *= 2 # fontsize == 12 on the label and both buttons