Question

I've created a window with menu and two notebook tabs. In the menu I have a button "Open" and it's opening me a file aaa.txt in a text widget in notebook tab 1. The problem is that I would like to open it not in tab 1 but in current selected/displayed/active notebook tab (could be tab 1 or tab 2). Code below:

proc CommandOpen { } {
    set f [open aaa.txt r]
    set x [read $f]
    .f.nb.f1.f11.t1 insert 1.0 $x
    close $f
}

wm title .  
wm geometry . 640x460  
pack [frame .f] -fill both  
pack [ttk::notebook .f.nb] -fill both  
.f.nb add [frame .f.nb.f1] -text "tab1"   
pack [frame .f.nb.f1.f11] -side top -fill both  
pack [text .f.nb.f1.f11.t1 -bg white] -side left -fill both  
.f.nb add [frame .f.nb.f2] -text "tab2"  
pack [text .f.nb.f2.t1 -bg white] -side left -fill both    
menu .mbar -borderwidth 1   
. configure -menu .mbar    
.mbar add cascade -label "File" -underline 0 -menu [menu .mbar.file -tearoff 0]  
set mf .mbar.file  
$mf add command -label "Open" -command CommandOpen -underline 0  

Thanks

Was it helpful?

Solution

You can get the currently selected tab index using:

.f.nb index current

This is documented on the manual page (it's the index method and the current tabid).


To get the slave widget which is managed by a particular tab, you index into the results of the tabs method. Overall, you get:

set currentSubwindow [lindex [.f.nb tabs] [.f.nb index current]]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top