[Go to BBS]
All articles in a thread
SubjectBind Text Variable with an element in a list
Article No431
Date: 2007/05/11(Fri) 14:54:35
ContributorWangWeizhen < >
Hi, All. There's a problem while I bind TextVaiable with an element in a list. Look at the script below:

At Last section, I would like to bind the Variable in KBFText to strlist[1] and strlist[2]. While I click the Button to refresh, the "str" and "strlist" both change. But only the Text which bind to "str" changes, the other two which bind to "strlist" do not change.


Can you give some help?

There is a long list to show at realtime.

FFS;
w=KBMainFrame["Date",f,Title->"SAD"];
b=Button[f,Text->"Refresh",Command:>refresh];

strlist={"000","000"};
str = "000";

refresh:=(
str = DateString[];
strlist={DateString[],"It's "//DateString[]};
Print[str];
Print[strlist[1]];
Print[strlist[2]];
);


cf=KBFComponentFrame[f,
Add->{
KBFGroup[Text->"Group1"],
KBFText[Text->"Time";],
KBFText[Variable:>str],
KBFText[Variable:>strlist[1]],
KBFText[Variable:>strlist[2]]
}
];
TkWait[];

Further more, can "For" loop be used while bind Variables to KBFText?
like:


For[i=1,i<=10,i++,
KBFText[Variable:>strlist[i]]];

SubjectRe: Bind Text Variable with an element in a list
Article No432
Date: 2007/05/12(Sat) 01:47:35
ContributorAkio Morita
> Hi, All. There's a problem while I bind TextVaiable with an element in a list. Look at the script below:
>
> At Last section, I would like to bind the Variable in KBFText to strlist[1] and strlist[2]. While I click the Button to refresh, the "str" and "strlist" both change. But only the Text which bind to "str" changes, the other two which bind to "strlist" do not change.
>
>
> Can you give some help?
>
In the case that symbol `foo' is binded to List object,
foo[_Real] is translated to Part operator foo[[_Real]].
Thus, your code fragment KBFText[Variable:>strlist[1]]
means KBFText[Variable:>strlist[[1]]].
In the Tkinter & KBFrame framework library,
both bare symbol (foo) and hashed symbol (foo[___])
can be used to Variable option. But, Parted symbol (foo[[__Real]])
can't be used to Variable option, because we can't override
Part[] intrinsic function by UpSetDelayed[]. (See Packages/Tkinter.n in detail)

Collected code is shown in below.
---------------------------------------
FFS;
w=KBMainFrame["Date",f,Title->"SAD"];
b=Button[f,Text->"Refresh",Command:>refresh];

strlist[1]="000";
strlist[2]="000";
str = "000";

refresh:=(
str = DateString[];
strlist[1]=DateString[];
strlist[2]="It's "//DateString[];
Print[str];
Print[strlist[1]];
Print[strlist[2]];
);


cf=KBFComponentFrame[f,
Add->{
KBFGroup[Text->"Group1"],
KBFText[Text->"Time";],
KBFText[Variable:>str],
KBFText[Variable:>strlist[1]],
KBFText[Variable:>strlist[2]]
}
];
TkWait[];
----------------------------------------

> Further more, can "For" loop be used while bind Variables to KBFText?
> like:
>
>
> For[i=1,i<=10,i++,
> KBFText[Variable:>strlist[i]]];
Shown code fragment is not collect, KBFText[] does not generate Text widget by itself.
Widgets are generated by KBFComponentFrame[] function, and KBFText[] is a configuration
information for KBFComponentFrame[] function.
Thus, I recommend to use Table/Map function insted of For loop.

Ex)
cf = KBFComponentFrame[f, Add->{
KBFGroup[Text->"Group2"],
Null@@Map[With[{i = #}, KBFText[Variable:>strlist[i]]]&, Range[10]]}];