Create new tkcon console to use in GUI
How could I go about creating a new tcl console to be used with a GUI that I'm building in Hypermesh ?
I tried using
package require tkcon tkcon new
But I get a message saying :
Can't find a usable init.tcl in the following directories: This probably means that Tcl wasn't installed properly.
Answers
-
Hi,
If you cannot create new tkcon, try attaching main console to your GUI by a proc like this:
proc ::SwitchTkCon {UserContainer} { set UserCID [winfo id $UserContainer] if {[.tkcon cget -use]==$UserCID]} { .tkcon configure -use $::SwitchTkCon } else { set ::SwitchTkCon [.tkcon cget -use] .tkcon configure -use $UserCID } } #example set w .yourGUI catch {destroy $w} toplevel $w frame $w.fTkCon -container 1 pack $w.fTkCon #attach tkcon to your gui: {invoke again to turn it back to command window} SwitchTkCon $w.fTkCon
0 -
Altair Forum User said:
Hi,
If you cannot create new tkcon, try attaching main console to your GUI by a proc like this:
proc ::SwitchTkCon {UserContainer} { set UserCID [winfo id $UserContainer] if {[.tkcon cget -use]==$UserCID]} { .tkcon configure -use $::SwitchTkCon } else { set ::SwitchTkCon [.tkcon cget -use] .tkcon configure -use $UserCID } } #example set w .yourGUI catch {destroy $w} toplevel $w frame $w.fTkCon -container 1 pack $w.fTkCon #attach tkcon to your gui: {invoke again to turn it back to command window} SwitchTkCon $w.fTkCon
Hi,
Thank you. This works perfectly. I was actually able to create a new slave console using tkcon new, how would I then go about tweaking your code so as to attach the new slave console to my GUI ?
0 -
How did you create new slave?
0 -
Altair Forum User said:
How did you create new slave?
I created the new slave console using
tkcon new
The only problem I have now is that I don't know the window pathname to this new slave console and I hence can't attach it to my GUI. I can still see the new console created on my screen but am just not able to attach it to my GUI.
Thanks.
0 -
Dear,
How did you overcome the above error?
0 -
I overcame that error by simply copying and pasting the tcl directory from the hyperview (hw) folder into the hypermesh (hm) folder.
0 -
Hi,
I did same to you but it does not work.
anyway, try my first method
0 -
Altair Forum User said:
Hi,
I did same to you but it does not work.
anyway, try my first method
@tinh : I did try the first method and it works well, although I needed to do the same with a slave console rather than the Tk main console, is there any way I could do that ?
0 -
Altair Forum User said:
@tinh : I did try the first method and it works well, although I needed to do the same with a slave console rather than the Tk main console, is there any way I could do that ?
Hi,
I can't create a slave, so I cannot try. Do you need a slave just to output information? think a simpler method
0 -
Altair Forum User said:
Hi,
I can't create a slave, so I cannot try. Do you need a slave just to output information? think a simpler method
@tinh : The issue is that my GUI is multi-tabbed and one of the tabs will have this tcl console on it. So when I try implementing your method it works perfectly on the tab that contains the console, but when I switch to another tab in the same GUI which does not have the console, I get the following error,
Error: invalid command name '.tkcon.tab1'
Which is why I thought that if I embed a slave console instead of the main tcl console, then this error would disappear. Any thoughts on how I could fix the above error ?
0 -
Hi,
please show your codes which create tabs. did you use ::ttk::notebook ?
anyway, tkconsole does not need to be packed in a tab. So try packing it in another widget on your GUI
0 -
Altair Forum User said:
Hi,
please show your codes which create tabs. did you use ::ttk::notebook ?
anyway, tkconsole does not need to be packed in a tab. So try packing it in another widget on your GUI
@tinh : Yes, I did use ::ttk::notebook to create the various tabs in my GUI. I haven't embedded the tkconsole in the tab itself, rather I've embedded it into a widget that is embedded into the tab as follows,
set frm_console [ frame $TestFrame.console ]; pack $frm_console -side top -anchor nw; frame $frm_console.fTkCon -container 1 pack $frm_console.fTkCon -side top; SwitchTkCon $frm_console.fTkCon
However, when I try switching tabs, I get the error I mentioned earlier in this post. Also, when I close my GUI and return to the HyperMesh main window, the tkconsole does not return to its original position but disappears instead. And there's no way I can get it back other than to restart HyperMesh.
0 -
You embeded tkcon into a widget which is embeded in tab ==> so you already embeded tkcon in tab
Please avoid it.
before close your GUI, invoke SwitchTkCon again to move tkcon to original position
0 -
Altair Forum User said:
You embeded tkcon into a widget which is embeded in tab ==> so you already embeded tkcon in tab
Please avoid it.
before close your GUI, invoke SwitchTkCon again to move tkcon to original position
@tinh : So then, how should I pack the tkconsole such that it's shown in the tab but not embedded into the tab ?
I invoked SwitchTkCon again on closing the GUI and the tkconsole was restored to its original position. Thanks for that suggestion.
0 -
Oh, it's very simple
example:
toplevel .tinh wm transient .tinh . set pw [ttk::panedwindow .tinh.pw -orient vertical] set nb [ttk::notebook $pw.nb] foreach i {1 2 3} {$nb add [frame $nb.f$i] -text tab$i} set fTkCon [frame $pw.fTkConContainer -container 1] $pw add $nb $pw add $fTkCon pack $pw -fill both -expand 1 wm protocol .tinh WM_DELETE_WINDOW { if {[winfo id .tinh.pw.fTkConContainer]==[.tkcon cget -use]} {SwitchTkCon .tinh.pw.fTkConContainer} destroy .tinh } SwitchTkCon $fTkCon
0 -
Altair Forum User said:
Oh, it's very simple
example:
toplevel .tinh wm transient .tinh . set pw [ttk::panedwindow .tinh.pw -orient vertical] set nb [ttk::notebook $pw.nb] foreach i {1 2 3} {$nb add [frame $nb.f$i] -text tab$i} set fTkCon [frame $pw.fTkConContainer -container 1] $pw add $nb $pw add $fTkCon pack $pw -fill both -expand 1 wm protocol .tinh WM_DELETE_WINDOW { if {[winfo id .tinh.pw.fTkConContainer]==[.tkcon cget -use]} {SwitchTkCon .tinh.pw.fTkConContainer} destroy .tinh } SwitchTkCon $fTkCon
@tinh : The above code works perfectly. However, my aim is to have the tkconsole in one of the three tabs, not in all of them and for the console to return to its original position once I close the GUI, how would I go about that ?
When I run the above code through File -> Run -> Tcl/Tk Script, a new GUI with three tabs and a tkconsole is created, and when I close the GUI, the tkconsole does not return to its original position.
0 -
Are you requesting me to write all codes for you?
tkcon is in one of three tabs, and tkcon moves to original position after closing
proc SwitchTkCon {WID} {.tkcon configure -use $WID} toplevel .tinh wm transient .tinh . set nb [::ttk::notebook .tinh.nb] pack $nb -fill both -expand 1 foreach i {1 2 3} {$nb add [frame $nb.f$i] -text tab$i} set fTkConContainer [frame $nb.f1.fTkCon -container 1] pack $fTkConContainer -fill both -expand 1 wm protocol .tinh WM_DELETE_WINDOW {SwitchTkCon $::tkcon::PRIV(frameId); update; destroy .tinh} SwitchTkCon [winfo id $fTkConContainer]
0