Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sourcing files

69 views
Skip to first unread message

mluc

unread,
Apr 3, 2017, 3:54:15 PM4/3/17
to
hi. I wonder if anyone can give me a hint on how to link several tcl files in just one.
I have my main function that generates a gui with different buttons to open other guis. ie. in my main function i have different proc that call other guis

proc GUI1 {} {
toplevel .createGui1Dlg
CreateGUI::init .createGui1Dlg
}

I have other three like this and I need to create just a file to be referenced in my main fuct.
can somebody can give me some started points?
thanks a lot

Bezoar

unread,
Apr 3, 2017, 8:04:07 PM4/3/17
to
From your description, you have 3 files that have the same CreateGUI::init function and your main function must call one of those but you want to select which one based on filename. So :

file1.tcl :
namespace eval CreateGUI {
proc init { toplevel } {
button $toplevel.b1 -text "file1.tcl" -command { puts "file1" }
pack $toplevel.b1 -side top -fill both -expand 1
}
}
file2.tcl :
namespace eval CreateGUI {
proc init { toplevel } {
button $toplevel.b2 -text "file2.tcl" -command { puts "file2" }
pack $toplevel.b2 -side top -fill both -expand 1
}
}
file3.tcl :
namespace eval CreateGUI {
proc init { toplevel } {
button $toplevel.b3 -text "file3.tcl" -command { puts "file3" }
pack $toplevel.b3 -side top -fill both -expand 1
}
}

main.tcl:
package require Tk
set filename [lindex $argv 0 ] ; # first arg on command line note this is
# problematic on windows

proc GUI1 { file } {
toplevel .createGui1Dlg
source $file
CreateGUI::init .createGui1Dlg
}

GUI1 $filename

to run on commmandline : tclsh8.6 main.tcl file1.tcl

mluc

unread,
Apr 6, 2017, 12:56:34 AM4/6/17
to
Thanks a lot. I did a little modification and worked perfecly linking all 3 file. thanks again
0 new messages