Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple word on screen

Status
Not open for further replies.

edwong

Programmer
Mar 26, 2003
30
US
Hi,
I have built a graphical interface using tk. Below is my problem.
I have a C++ function to output different strings. I would like them to appear in the interface. Rite now, I only know how to output one string.

I use

string a;
sprintf(buffer, ".c1 configure -text %s", a.c_str());
Tcl_Eval(globalinterp,buffer);

in my tk file, i have
label .word -text "The word is: "
label .c1 -text ""

how can i modify this to satisy multi string in the screen?

thx
 
The chunk of text that you provide to Tcl_Eval has to follow the same syntax as any Tcl command you'd execute in a script. And the following line doesn't work because the string isn't provided as a single argument to the -text option:

Code:
.c1 configure -text Hello World

Probably the safest thing to do, assuming that you don't want any substitutions to occur on the string that you're trying to display, is to quote the argument using {}:

Code:
sprintf(buffer, ".c1 configure -text {%s}", a.c_str());
- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Thanks for the help
I have use {%s}, so now i can output multiple strings on one line

But how can you modify it to output mulit lines of strings on the interface (getting the strings from the C++ program?)

thx
 
Simply embed newline characters into the string. By the way, if you're going to be displaying several lines of text, you might want to consider using a text widget instead of a simple label. The text widget will give you much greater control over the appearance of the output (e.g., multiple fonts, colors, sizes, etc.). - Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top