Incorrect return of the TkFont configure instance method when no value

L

Lionel MAIAUX

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
 
M

Morton Goldberg

Try

require 'tk'
font = TkFont.new
size = font.size #=> 12 (on my system)

Regards, Morton
 
H

Hidetoshi NAGAI

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: said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top