Home > Archive > Tcl > January 2008 > Missing bindings when running a Tk app from C
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Missing bindings when running a Tk app from C
|
|
| SimonG 2008-01-29, 9:00 am |
| In my previous post (Getting focus in Tk app started from C++ ) I
incorrectly assummed that the problem was due to focus not being
correctly assigned. I was wrong about that. The problem is that when
the interpreter is started through a C++ program most of the bindings
are missing. I presume that this is desired behaviour but I don't
understand why or what the recommended way is to restore the bindings
to their script defaults. The following program illustrates the
problem - running as a script gives 37 'Listbox' bindings and 10 'all'
bindings. Running the same program from the C++ gives 0 'Listbox'
bindings and 8 'all' bindings.
Once again any help would be grately appreciated.
Simon Geard
*** tkw.tcl
package require Tk
if {! [info exists ::tkwData]} {
set ::tkwData {{No Data}}
}
set lb [listbox .lb -takefocus 1 -width 60 -height 40]
pack $lb -fill both -expand 1
..lb insert end {*}$::tkwData
..lb itemconfigure 0 -foreground red -background yellow
..lb insert end "[llength [bind Listbox]] 'Listbox' bindings"
foreach b [bind Listbox] {
.lb insert end "$b"
.lb itemconfigure end -foreground green -background yellow4
}
..lb insert end "[llength [bind all]] 'all' bindings"
foreach b [bind all] {
.lb insert end "$b"
.lb itemconfigure end -foreground green -background yellow4
}
***tkw.cxx
#include "tk.h"
static int appInitProc(Tcl_Interp *interp) {
Tk_Init(interp);
// Run tkw.tcl with this interp
Tcl_EvalFile(interp, "tkw.tcl");
// Wait for the main loop to exit
Tk_MainLoop();
return TCL_OK;
}
int main(int argc, char** argv) {
Tk_Main(argc, argv, appInitProc);
return 0;
}
| |
| Koen Danckaert 2008-01-30, 7:46 pm |
| On 29 jan, 15:44, SimonG <si...@whiteowl.co.uk> wrote:
> In my previous post (Getting focus in Tk app started from C++ ) I
> incorrectly assummed that the problem was due to focus not being
> correctly assigned. I was wrong about that. The problem is that when
> the interpreter is started through a C++ program most of the bindings
> are missing. I presume that this is desired behaviour but I don't
> understand why or what the recommended way is to restore the bindings
> to their script defaults. The following program illustrates the
> problem - running as a script gives 37 'Listbox' bindings and 10 'all'
> bindings. Running the same program from the C++ gives 0 'Listbox'
> bindings and 8 'all' bindings.
>
>
> #include "tk.h"
>
> static int appInitProc(Tcl_Interp *interp) {
>
> Tk_Init(interp);
Maybe you forgot Tcl_Init(interp), which has to be done before
Tk_Init(interp).
--Koen
| |
| SimonG 2008-01-30, 7:46 pm |
| On Jan 30, 1:57 pm, Koen Danckaert <koen.n...@gmail.com> wrote:
> On 29 jan, 15:44, SimonG <si...@whiteowl.co.uk> wrote:
>
>
>
>
>
>
>
> Maybe you forgot Tcl_Init(interp), which has to be done before
> Tk_Init(interp).
>
> --Koen
Thanks very much - that has solved the problem.
Simon.
|
|
|
|
|