Swati Verma
Swati Verma

Reputation: 13

Place combobox on a frame of a ttk::notebook

I want to put a combobox over a frame of a tk notebook. I arrange the frame and the components using grid. When i place the combobox over the frame, the frame in the background disappears. What can be the reason for this? My code is as follows:

ttk::notebook .f.n  -width 1600 -height 800
frame .f.n.f1
frame .f.n.f2 
.n add .f.n.f1 -text "TabOne" 
.n add .f.n.f2 -text "TabTwo"
grid .f.n -sticky news -row 0 -column 0
#Code to create a side menu
 grid [frame .f.n.TabOne.m -width 200 -height 800] -sticky news -row 0 -column 0
 grid [ttk::combobox .f.n.Tabone.m.d -values {"val 1" "val 2"}] -sticky news

Upvotes: 0

Views: 203

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137587

To put a combobox within a tab's pane, you have to make it a child of the widget (usually a frame — and definitely so in your case — but not necessarily) that is the interior of the tab. Otherwise it is not inside, but rather just stacked on top.

The easiest way of getting this consistently right is to build widget names from variables that reference their parents. Idiomatically, you store the name returned by the widget construction function and then build the child names by simple concatenation, like this:

set nb [ttk::notebook .f.n -width 1600 -height 800]
set tab_one [frame $nb.f1]
set tab_two [frame $nb.f2]
$nb add $tab_one -text "TabOne" 
$nb add $tab_two -text "TabTwo"
grid $nb -sticky news -row 0 -column 0

#Code to create a side menu
grid [frame $tab_one.m -width 200 -height 800] -sticky news -row 0 -column 0
grid [ttk::combobox $tab_one.m.d -values {"val 1" "val 2"}] -sticky news

Upvotes: 0

Related Questions