For Programmers: Free Programming Magazines  


Home > Archive > Ruby > August 2005 > tk variables









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author tk variables
csjasnoch@wisc.edu

2005-08-29, 7:02 pm

Is it possible to initialize the tk variables so the effect is shown in
say buttons.

For example a checkbox:

check1 = TkVariable.new
TkCheckButton.new(buttonFrm){
variable check1
command active1ButtonChecked
}.pack('side'=>'left')

The idea is I want it to open as my file states it should... So I have
a string
0:0:0:1:0:1:0:0:0


so if these were some check box variables when the program starts there
is read and I want to initialize the 4th and 6th check box to
"checked" and the rest unchecked.

I also want to be able to do this with buttons with image binded.

Thank you for you help.

csjasnoch@wisc.edu

2005-08-29, 7:02 pm

I am able to handle the button image as I had already created a method
to handle this. Now I just do a call to this durring initialize (after
my file has been read)... however I can't find away to configure check
boxes.

Hidetoshi NAGAI

2005-08-30, 3:57 am

From: "csjasnoch@wisc.edu" <csjasnoch@wisc.edu>
Subject: tk variables
Date: Tue, 30 Aug 2005 00:51:22 +0900
Message-ID: <1125330668.043332.268500@g43g2000cwa.googlegroups.com>
> For example a checkbox:
>
> check1 = TkVariable.new
> TkCheckButton.new(buttonFrm){
> variable check1
> command active1ButtonChecked
> }.pack('side'=>'left')
>
> The idea is I want it to open as my file states it should... So I have
> a string
> 0:0:0:1:0:1:0:0:0


TkVariable.new accepts an initial value.
For example,
-------------------------------------------------
buttonFrm = TkFrame.new.pack
s = '0:0:0:1:0:1:0:0:0:1:0:0'
v_list = []
s.split(':').each_with_index{|val, idx|
v_list << (v = TkVariable.new(val))
TkCheckButton.new(buttonFrm, :variable=>v,
:text=>"state #{idx}").pack(:anchor=>:w, :fill=>:x)
}
-------------------------------------------------

> I also want to be able to do this with buttons with image binded.


Please use 'image', 'selectimage' and 'indicatoron' option of
checkbutton widgets.

# See also "icon.rb" which is part of "Ruby/Tk widget demo"
# ( <ruby source>/ext/tk/sample/demo-en/ ).
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com