Forum: Ruby Ruby/Tk : Accessing a Checkbox

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
26198eab52c6dcded426d133703828ec?d=identicon&s=25 unknown (Guest)
on 2006-02-23 14:49
(Received via mailing list)
How can I find out whether a Checkbox is checked or unchecked in Ruby?

Here is my Checkbox definition (hope it is correct):

  $bpmto_check=TkCheckButton.new(bpmto_frame);

How can I find the state of the checkbox? I tried the .value
member (like in the entry field), but this is not defined
for checkboxes.

I have searched several tutorials on Ruby/Tk, but did not find
one which covers checkboxes. Is there a reference manual
available, or man pages, which covers the Tk extensions of Ruby?

Ronald
Fafbe7fc27ab8e96a7cb732de5039a87?d=identicon&s=25 unknown (Guest)
on 2006-02-23 15:19
(Received via mailing list)
> I have searched several tutorials on Ruby/Tk, but did not find
> one which covers checkboxes. Is there a reference manual
> available, or man pages, which covers the Tk extensions of Ruby?
>
> Ronald

You need a TkVariable associated with the checkbutton.

var = TkVariable.new

$pbmto_check = TkCheckButton.new(pbmto_frame) do
    variable var
    pack
end
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 Hidetoshi NAGAI (Guest)
on 2006-02-23 16:11
(Received via mailing list)
From: dperkins@frii.com
Subject: Re: Ruby/Tk : Accessing a Checkbox
Date: Thu, 23 Feb 2006 23:19:18 +0900
Message-ID: <1311.63.77.210.130.1140704341.squirrel@users.frii.com>
> You need a TkVariable associated with the checkbutton.
>
> var = TkVariable.new
>
> $pbmto_check = TkCheckButton.new(pbmto_frame) do
>     variable var
>     pack
> end

Latest Ruby/Tk supports a default variable of a checkbutton.
So, you don't need define a TkVariable. For example,
-------------------------------------------------------------
irb(main):002:0> $pbmto_check = TkCheckButton.new(pbmto_frame)
=> #<TkCheckButton:0xb7c48a8c @path=".w00000.w00001">
irb(main):003:0> $pbmto_check.get_value
=> "0"
irb(main):004:0> $pbmto_check.set_value(1)
=> "1"
irb(main):005:0> $pbmto_check.get_value
=> "1"
irb(main):006:0> $pbmto_check.variable
=> #<TkVariable: w00001>
irb(main):007:0> $pbmto_check.variable.value
=> "1"
irb(main):008:0> TkUtil.bool($pbmto_check.get_value)
=> true
irb(main):009:0> $pbmto_check.variable.bool
=> true
irb(main):010:0> $pbmto_check.variable.value = 0
=> 0
irb(main):011:0> $pbmto_check.get_value
=> "0"
irb(main):012:0> TkUtil.bool($pbmto_check.get_value)
=> false
irb(main):013:0> $pbmto_check.variable.value
=> "0"
irb(main):014:0> $pbmto_check.variable.bool
=> false
irb(main):015:0> $pbmto_check.variable.numeric
=> 0
Fafbe7fc27ab8e96a7cb732de5039a87?d=identicon&s=25 unknown (Guest)
on 2006-02-23 18:09
(Received via mailing list)
> Latest Ruby/Tk supports a default variable of a checkbutton.
> So, you don't need define a TkVariable. For example,
> -------------------------------------------------------------
> irb(main):002:0> $pbmto_check = TkCheckButton.new(pbmto_frame)
> => #<TkCheckButton:0xb7c48a8c @path=".w00000.w00001">
> irb(main):003:0> $pbmto_check.get_value
> => "0"

Great!  I'll add this to my Rubyt/Tk notes.
This topic is locked and can not be replied to.