Home > Archive > Tcl > January 2008 > Getting focus in Tk app started 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 |
Getting focus in Tk app started from C++
|
|
| SimonG 2008-01-28, 9:02 am |
| I'm experimenting with driving a tk app from source code (8.5). The
problem I'm having with the code below is getting focus into the
listbox. I have tried both WinXP and Linux but the results are the
same - a listbox is displayed with the correct (2,4,6,8) data but I
cannot get focus into it. Any ideas on how to get the focus behaving
properly would be gratefully received.
Thanks,
Simon Geard
*** C++ source code:
#include "tk.h"
static int appInitProc(Tcl_Interp *interp) {
Tk_Init(interp);
// Put data into a list
int objc = 4;
Tcl_Obj* const objv[4] = {
Tcl_NewIntObj(2),
Tcl_NewIntObj(4),
Tcl_NewIntObj(6),
Tcl_NewIntObj(8)
};
Tcl_Obj* data_l = Tcl_NewListObj(objc, objv);
// Add list object to interp with name ::tkwData
Tcl_SetVar2Ex(interp, "::tkwData", NULL, data_l, 0);
// 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;
}
*** Tcl source code (tkw.tcl):
package require Tk
set lb [listbox .lb -takefocus 1]
pack $lb -fill both -expand 1
if {[info exists ::tkwData]} {
.lb insert end {*}$::tkwData
} else {
.lb insert end "No Data" a b c d
.lb itemconfigure 0 -foreground red -background yellow
}
| |
| Ron Fox 2008-01-28, 7:43 pm |
| At the end of your tkw.tcl script add:
focus .lb
RF
SimonG wrote:
> I'm experimenting with driving a tk app from source code (8.5). The
> problem I'm having with the code below is getting focus into the
> listbox. I have tried both WinXP and Linux but the results are the
> same - a listbox is displayed with the correct (2,4,6,8) data but I
> cannot get focus into it. Any ideas on how to get the focus behaving
> properly would be gratefully received.
>
> Thanks,
>
> Simon Geard
>
>
> *** C++ source code:
>
> #include "tk.h"
>
>
> static int appInitProc(Tcl_Interp *interp) {
>
> Tk_Init(interp);
>
> // Put data into a list
> int objc = 4;
> Tcl_Obj* const objv[4] = {
> Tcl_NewIntObj(2),
> Tcl_NewIntObj(4),
> Tcl_NewIntObj(6),
> Tcl_NewIntObj(8)
> };
> Tcl_Obj* data_l = Tcl_NewListObj(objc, objv);
>
> // Add list object to interp with name ::tkwData
> Tcl_SetVar2Ex(interp, "::tkwData", NULL, data_l, 0);
>
> // 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;
> }
>
>
> *** Tcl source code (tkw.tcl):
> package require Tk
>
> set lb [listbox .lb -takefocus 1]
> pack $lb -fill both -expand 1
>
> if {[info exists ::tkwData]} {
> .lb insert end {*}$::tkwData
> } else {
> .lb insert end "No Data" a b c d
> .lb itemconfigure 0 -foreground red -background yellow
> }
| |
| SimonG 2008-01-28, 7:43 pm |
| Thank you for your suggestion. Unfortunately it doesn't work - the
parent window has focus not the widget. The script works as expected
when run directly, it is only when driving it through an external
program that the problem arises.
Regards,
Simon
On Jan 28, 3:10 pm, Ron Fox <f...@nscl.msu.edu> wrote:[color=darkred]
> At the end of your tkw.tcl script add:
>
> focus .lb
>
> RF
>
> SimonG wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
| |
| Óscar Fuentes 2008-01-28, 7:43 pm |
| SimonG <simon@whiteowl.co.uk> writes:
> Thank you for your suggestion. Unfortunately it doesn't work - the
> parent window has focus not the widget. The script works as expected
> when run directly, it is only when driving it through an external
> program that the problem arises.
focus -force .lb
--
Oscar
| |
| SimonG 2008-01-28, 7:43 pm |
| Thank you for your suggestion. Unfortunalely it doesn't work (have
just tried it on both WinXP and Linux).
Simon
On Jan 28, 4:06 pm, =D3scar Fuentes <o...@wanadoo.es> wrote:
> SimonG <si...@whiteowl.co.uk> writes:
>
> focus -force .lb
>
> --
> Oscar
| |
| SimonG 2008-01-28, 7:43 pm |
| I've done some more investigation and what seems to be hapenning is
that the created widget seems to have lost all its bindings, so that
in particular selection is not working. Focus is, I think, working ok.
Simon
On 28 Jan, 16:21, SimonG <si...@whiteowl.co.uk> wrote:[color=darkred]
> Thank you for your suggestion. Unfortunalely it doesn't work (have
> just tried it on both WinXP and Linux).
>
> Simon
>
> On Jan 28, 4:06 pm, =D3scar Fuentes <o...@wanadoo.es> wrote:
>
>
>
|
|
|
|
|