C++/Tk
A complete C++ interface to the Tk GUI toolkit
SourceForge.net Logo

Home
Download
Documentation
Examples
People
Events
Links
Example: [1] [2] [3] [4] [5] [6]

Screenshot:

Example2

What it does:

It displays the button and prints the greetings on the console when the button is pressed.
This is the same example as on the homepage, but with error handling added.

Source code:

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

using namespace Tk;
using namespace std;

void sayHello()
{
     cout << "Hello C++/Tk!" << endl;
}

int main(int, char *argv[])
{
     try
     {
          init(argv[0]);
         
          button(".b") -text("Say Hello") -command(sayHello);
          pack(".b") -padx(20) -pady(6);
         
          runEventLoop();
     }
     catch (exception const &e)
     {
          cerr << "Error: " << e.what() << '\n';
     }
}