StarCoder17
StarCoder17

Reputation: 175

tk notebook frame is not resizing properly, when widgets are added

I am using ttk:notebook for creating frames. Attaching children's to these slaves, but it didn't resize properly, when listbox widget gets created. I am using following code:

ttk::notebook .top.d  -width 880 -height 600 -padding 5
ttk::frame .top.d.f1;
ttk::frame .top.d.f2;
.top.d add .top.d.f2 -text "Memory Characterization" -padding 5
.top.d add .top.d.f1 -text "Standard cells Characterization" -padding 5

When more widgets are added they hide, until i have to manually resize it.

Upvotes: 0

Views: 456

Answers (2)

Dcode
Dcode

Reputation: 223

I would recommend to use relative placement of child widgets w.r.t your notebook by using Place geometry manager

Upvotes: 0

Uwe Koloska
Uwe Koloska

Reputation: 478

As Jerry said, what did you expect, when giving a width and height?

Maybe your confusion comes from the width resizing when adding notebook tabs, but this is by intention, because otherwise you cannot see all configured tabs. Unfortunately there is no standard code for scrolling tab headers.

The following code shows the effect:

#!/usr/bin/env wish

set conf(width) 200
set conf(height) 100

ttk::button .b1 -command addNewPage -text "Add"
ttk::button .b2 -command toggleSize -text "Toggle Size"
ttk::notebook .d -width 200 -height 100 -padding 5
grid .b1 .b2
grid .d - -sticky eswn
grid columnconfigure . all -weight 1
grid rowconfigure . 2 -weight 1

set numpages 0
set pages [dict create \
               .d.f1 "Memory Characterization" \
               .d.f2 "Standard cells Characterization" \
               .d.f3 "Just another long title" \
               .d.f4 "Hope this is long enough"]

proc addNewPage {} {
    variable pages
    variable numpages

    if {$numpages < [dict size $pages]} {
        set w [lindex [dict keys $pages] ${numpages}]
        ttk::frame $w
        set title [dict get $pages $w]
        .d add $w -text $title -padding 5
        addChildren $w
        incr numpages
        if {$numpages >= [dict size $pages]} {
            .b configure -state disabled
        }
    }
}

proc addChildren {w} {
    for {set i 1} {$i < 9} {incr i} {
        for {set j 1} {$j < 9} {incr j} {
            grid [ttk::button $w.b$i$j -text "Button $i:$j"] -row $i -column $j -padx 5 -pady 5
        }
    }
}

proc toggleSize {} {
    variable conf

    if {[.d cget -width] == $conf(width)} {
        set width 0
        set height 0
    } else {
        set width $conf(width)
        set height $conf(height)
    }
    .d configure -width $width -height $height
}

Upvotes: 1

Related Questions