Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6095287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:47:43+00:00 2026-05-23T12:47:43+00:00

So we have code like: #include cpptk.h #include <stdio.h> using namespace Tk; void hello()

  • 0

So we have code like:

#include "cpptk.h"
#include <stdio.h>

using namespace Tk;

void hello() {
     puts("Hello C++/Tk!");
}

int main(int, char *argv[])
{
    static char* str = "button .a -text "Say Hello ppure TCL"\n"
                   "pack .a\n";
     init(argv[0]);

     button(".b") -text("Say Hello") -command(hello);
     pack(".b") -padx(20) -pady(6);

     runEventLoop();
}

imagine str is complex tcl code. We want to feed it to C++/Tk as a string. Also we want to have it exequted in the same TCL vm our general C++/Tk programm with gui we created in C++/Tk code runs. So the result of this code would be 2 buttons inside a window.
How to do such thing?

How to do such thing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:47:43+00:00Added an answer on May 23, 2026 at 12:47 pm

    Have you got access to the Tcl_Interp* handle used inside C++/Tk? If so (and assuming here you’ve got it in a variable called interp) use:

    int resultCode = Tcl_Eval(interp, str);
    

    Next, check the resultCode to see if it is TCL_OK or TCL_ERROR (other values are possible, but uncommon in normal scripts). That tells you the interpretation of the “result”, which you get like this:

    const char *result = Tcl_GetString(Tcl_GetObjResult(interp));
    

    If the result code says its an error, result is now an error message. If it was ok, the result is the output of the script (NB: not what was written to standard out though). It’s up to you what to do with that.


    [EDIT]: I looked this up in more detail. It’s nastier than it appears, because C++/Tk hides away Tcl quite deep inside itself. In so far as I can see, you do this (untested!):

    #include "cpptk.h" // might need "base/cpptkbase.h" instead
    #include <string>
    
    // This next part is in a function or method...
    std::string script("the script to evaluate goes here");
    std::string result = Tk::details::Expr(script,true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have a C code like this: #include <stdio.h> int main(){ printf("Hello, world!\n");
I have C code like this: #include<stdio.h> int main() { printf(Hey this is my
I have the code like this : #include <stdio.h> main() { int c; c
If I have a global static variable x like in this code #include <stdio.h>
Suppose I have code something like this: #include boost/thread/mutex.hpp using boost::mutex; typedef mutex::scoped_lock lock;
I have code like this: ... entry.KeyPressEvent += EntryKeyPressEvent; ... } void EntryKeyPressEvent(object o,
I have this code: #include <stdio.h> #include <stdlib.h> #include <signal.h> // Define the function
i have some Linq to Entity code like so: var tablearows = Context.TableB.Include(TableA).Where(c =>
Im using Ubuntu 10.10, Code::Blocks with GCC 4.2. I have written a code like
I'm using LLBLGen and I have some code like so: if (onlyRecentMessages) { messageBucket.PredicateExpression.Add(MessageFields.DateEffective

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.