Ruby/Tk : Accessing a Checkbox

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

···

--
Sent by mn-pg-p-e-b-consultant-3.com from siemens subdomain of com
This is a spam protected message. Please answer with reference header.
Posted via http://www.usenet-replayer.com

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

You need a TkVariable associated with the checkbutton.

var = TkVariable.new

$pbmto_check = TkCheckButton.new(pbmto_frame) do
    variable var
    pack
end

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,

···

From: dperkins@frii.com
Subject: Re: Ruby/Tk : Accessing a Checkbox
Date: Thu, 23 Feb 2006 23:19:18 +0900
-------------------------------------------------------------
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
-------------------------------------------------------------
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

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.