+TK from C

This commit is contained in:
anon 2024-12-10 20:38:37 +01:00
parent 02f9da042a
commit 0cfe4e6352
2 changed files with 48 additions and 0 deletions

41
C_C++/Tcl/button_help.c Normal file

@ -0,0 +1,41 @@
// @BAKE gcc $@ -o $*.out $(pkg-config --cflags --libs tcl tk)
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <tcl.h>
#include <tk.h>
// our button callback
static
int Tcl_baah(ClientData clientData, Tcl_Interp * interp, int argc, const char * * argv) {
puts("BAAAAAAAH");
return TCL_OK;
}
static
void tcl_run(void) {
Tcl_Interp * interp = Tcl_CreateInterp();
Tcl_Init(interp);
Tk_Init(interp);
Tcl_CreateCommand(interp, "baah", Tcl_baah, (ClientData)NULL, (void (*)())NULL);
/* if only it were past 2023 we could have #embed!
* oh wait...
*/
int result = Tcl_EvalFile(interp, "button_help.tcl");
if (result == TCL_ERROR) {
fprintf(stderr, "Tcl script execution failed: %s\n", Tcl_GetStringResult(interp));
exit(1);
}
Tk_MainLoop();
}
signed main() {
pthread_t tcl_thread;
pthread_create(&tcl_thread, NULL, (void *(*)(void*))tcl_run, (void*)NULL);
// whatever you want
while (1) { ; }
}

@ -0,0 +1,7 @@
package require Tk
wm title . "Button example"
frame .main
pack .main
button .mybutton -text "press me" -command baah
pack .mybutton