# Incorrect return of the TkFont configure instance method whe

**URL:** <https://www.ruby-forum.com/t/incorrect-return-of-the-tkfont-configure-instance-method-whe/67051>\
**Category:** Ruby\
**Created:** [August 31, 2006, 10:11am UTC](https://www.ruby-forum.com/t/incorrect-return-of-the-tkfont-configure-instance-method-whe/67051 "2006-08-31T10:11:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lionel\_MAIAUX](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@Lionel\_MAIAUX](https://www.ruby-forum.com/u/Lionel_MAIAUX)\
**Post date:** [August 31, 2006, 10:11am UTC](https://www.ruby-forum.com/t/incorrect-return-of-the-tkfont-configure-instance-method-whe/67051/1 "2006-08-31T10:11:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lionel\_MAIAUX](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@Lionel\_MAIAUX](https://www.ruby-forum.com/u/Lionel_MAIAUX)\
**Post date:** [August 31, 2006, 11:27pm UTC](https://www.ruby-forum.com/t/incorrect-return-of-the-tkfont-configure-instance-method-whe/67051/2 "2006-08-31T23:27:16Z")

</div>

Try

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

```

Regards, Morton

---

<div class="post-metadata">

**Author:** ![Lionel\_MAIAUX](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@Lionel\_MAIAUX](https://www.ruby-forum.com/u/Lionel_MAIAUX)\
**Post date:** [August 31, 2006, 11:35pm UTC](https://www.ruby-forum.com/t/incorrect-return-of-the-tkfont-configure-instance-method-whe/67051/3 "2006-08-31T23:35:17Z")

</div>

From: Lionel MAIAUX [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Incorrect return of the TkFont configure instance method when  
no value  
Date: Thu, 31 Aug 2006 17:09:14 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> 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
