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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating wish-like app with Tk_Main

Status
Not open for further replies.

nater

Programmer
Jun 14, 2002
21
CA
Hi. I'm trying to run a TK script from a c++ program using Tk_Main. It all works, but by default, Tk_Main creates an interactive shell. Instead, I just want to run a script (file), then exit. (So all I would get is the wish-like window, not the console. I've tried setting

Tcl_SetVar(interp, &quot;tcl_rcFileName&quot;, &quot;<script file>&quot;, TCL_GLOBAL_ONLY);

where <script file> is the script I want to run, in Tcl_AppInit. This works to run the script, but it still has the console window open in the background. Is there a way to do this through Tk_Main and the AppInit functions, or do I have to do something manually?

I noticed in the Tk_Init manual page:

If there is a variable argv in interp, Tk_Init treats the contents of this variable as a list of options for the new Tk application. The options may have any of the forms documented for the wish application (in fact, wish uses Tk_Init to process its command-line arguments).

And I know that if you give a filename argument to wish, it runs that script instead of opening the console, but I'm not sure how to set argv &quot;in&quot; interp.

Thanks for any help..
 
OK, so I answered my own question by downloading the source code and actually looking at Tk_Main (something I suggest for almost anyone if you're stuck. The source code is really amazingly easy to follow..)

Anyway, the default Tk_Main function (Actually Tk_MainEx - Tk_Main is just a macro that points there, presumably so that you don't have to specify the interpretter as an argument.) - Tk_Main function checks for the existance of an argv[1] that doesn't begin with a '-'. If found, it executes the script filename given by that string. Otherwise, it first executes the tcl_rcFileName I mentioned above, then enters an interactive loop.

So if you want to avoid the loop, you can either enter the script as a command line arg to your C program, manually insert it *in* the program, or modify Tk_MainEx (which wouldn't be hard to do, but is undesirable..)

Now I just have to figure a way to insert a string into an array of strings dynamically.. (I wish I could use TCL for this part! =) )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top