-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample3.cc
More file actions
48 lines (36 loc) · 1.01 KB
/
example3.cc
File metadata and controls
48 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "cpptk.h"
#include <iostream>
using namespace Tk;
using namespace std;
// these variables are used to communicate with widgets
string str;
int len;
// 'check' validates user input
bool check(string const &s)
{
return s.size() <= 12;
}
void compute()
{
len = static_cast<int>(str.size());
}
int main(int, char *argv[])
{
try
{
init(argv[0]);
label(".lab1") -text("strlen(");
// create entry widget with validation
entry(".e1") -textvariable(str) -validate(key)
-validatecommand(check, valid_P) -width(20);
label(".lab2") -text(")");
button(".b") -text(" = ") -command(compute);
entry(".e2") -textvariable(len) -width(5) -justify(Tk::right);
pack(".lab1", ".e1", ".lab2", ".b", ".e2") -side(Tk::left) -padx(5);
runEventLoop();
}
catch (exception const &e)
{
cerr << "Error: " << e.what() << '\n';
}
}