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

Layout for ttk::paned and ttk::labelframe

42 views
Skip to first unread message

Michael

unread,
May 14, 2007, 6:55:22 PM5/14/07
to
Hi,

I've almost complete the first part of the GUI for my application. It
is a database for telephone numbers and addresses. One of the key
features is that from the postcode the address is automatically
retieved from either database or from ain nternet web service. This
allows recognition of customer address (from telephone number), quick
entering of data and makes entering of data less error prone.

What I'm having problem is with the layout of widgets. I have a
ttk::paned as the top widget. This holds four ttk::labelframe's with a
virtical orientation. The top frame contains the telephone and
postcode entry boxes. The second frame contains an entry box for the
address. The third frame contains a list of address that is associated
with the postcode. A user can select an address from the list and this
will populate the entry address box. If a user enters characters in
the address entry box this will cause the closest matched address in
the address list to be selected and focused on. The bottom frame
contains a keyboard which can be used for entering details in the
entry boxes.

All this is implemented, however, I'm having trouble making the layout
do what I want. Currently the Telephone and Postcode label texts are
centered in it's own row. How can I left justify this?

The listbox does not fill the width of the frame. How can I do this.

The scrollbar is positioned somewhere to the "near" right. How can I
make the scrollbar positioned to the right of the frame?

Finally, the scrollbar is two narrow. I think on an 8inch touch screen
it will be harder to move the scrollbar. How can I make this wider?

M.

Here is the code so far:

package require Tk
package require tile

option add *font "Helvetica 20"
option add *background white
option add *background white

option add *tearOff false

style configure Big.TLabel -font {Helvetica 20}
style configure Big.TButton -font {Helvetica 20}

array set ::V {
COMPOUND top
CONSOLE 0
MENURADIO1 One
PBMODE determinate
SELECTED 1
CHOICE 2
SCALE 50
VSCALE 0
}
set ::none ""
variable TOP "."
variable TOP [ttk::frame .base]
pack $TOP -side top -expand true -fill both

set pw [ttk::paned $TOP.client -orient vertical ]

## Telephone Number and PostCode
set l2 [ttk::labelframe $pw.l2 -padding 0 -underline 0]
ttk::entry $l2.tel_num -textvariable ::tel_num
ttk::label $l2.1 -text Telephone
grid $l2.1 $l2.tel_num -sticky ew -padx 2 -pady 2
ttk::entry $l2.postcode -textvariable ::postcode
ttk::label $l2.2 -text Postcode
grid $l2.2 $l2.postcode -sticky ew -padx 2 -pady 2
$pw add $l2 -weight 1
grid columnconfigure $l2 {0 1} -weight 1
grid rowconfigure $l2 7 -weight 1 ;

set selection [list a b c d e f g h i j k l m n o p o r s t abc ac ad
af ag]
set ::addr ""
proc addressInput {w s a} {
set i 0
set match 0
puts "addressInput $w $s $a"
foreach item $::selection {
if {[string match -nocase $::addr${s} $item]} {
$::pw.l.lb selection clear 0 end
$::pw.l.lb selection set $i
$::pw.l.lb yview $i
set match 1
break
}
incr i
}
set i 0
if {!$match} {
set match 0
foreach item $::selection {
if { [string first [string tolower $::addr${s}] [string
tolower $item]] > -1} {
$::pw.l.lb selection clear 0 end
$::pw.l.lb selection set $i
$::pw.l.lb yview $i
}
incr i
}
}
return 1
}

## Address
set l3 [ttk::labelframe $pw.l3 -padding 0 -underline 0]
ttk::entry $l3.addr -textvariable ::addr -validate key -
validatecommand [list addressInput $l3 %S %d]
grid $l3.addr -sticky ew -padx 2 -pady 2
$pw add $l3 -weight 1
grid columnconfigure $l3 0 -weight 1
grid rowconfigure $l3 7 -weight 1

# List of address retrieved
set l [ttk::labelframe $pw.l -padding 0 -underline 0]
$pw add $l -weight 1
grid columnconfigure $l 0 -weight 1
grid rowconfigure $l 7 -weight 1
scrollbar $l.sb -command "$l.lb yview"
listbox $l.lb -yscroll "$l.sb set" -height 5
pack $l.lb $l.sb -side left -fill y -expand 1

set i 0
foreach item $selection {
$l.lb insert $i $item
incr i
}
proc hello { w } {
puts "hello $w [lindex $::selection [$w curselection]]"
set ::addr [lindex $::selection [$w curselection]]
}
bind all <<ListboxSelect>> [list hello %W]
bind all <MouseWheel> [list scrollListbox $l.lb %D]

proc scrollListbox {listbox delta} {
$listbox yview scroll [expr {- ($delta / 120) * 4}] units
}

proc guidisplay { in } {
upvar $in details

foreach item "tel_num property_id road town county postcode" {
if {[info exists details($item)]} {
set ::$item $details($item)
}
}
catch {unset details}
}

proc guigetdetails {l} {
getdetails [$l.tel_num get] [$l.postcode get] [$l.property_id
get] details
guidisplay details
}

proc keyAction {key} {
set Focus(Widget) [focus]

if {$Focus(Widget) != "\."} {
set eVar [lindex [split $Focus(Widget) \.] end]
} else {
set eVar none
}
if {$key == ""} {
set key " "
}
switch -exact $key {
"123" {
destroy $::BASE.keyboard
makeKeyboard $::keys(123)
}
"ABC" {
destroy $::BASE.keyboard
makeKeyboard $::keys(abc)
}
"BACK" {
set ::$eVar [string range [set ::${eVar}] 0 end-1]
}
"DEL" {
set ::$eVar ""
}
"DONE" {
guigetdetails $::pw.l
}
default {
if {$Focus(Widget) != "\."} {
addressInput $::l3.addr $key 1
append ::$eVar $key
set pos [string length [set ::$eVar]]
if {$pos > -1} {
$Focus(Widget) icursor $pos
}

}

}
}
}

proc shutdown {} {
destroy .
}
set keys(abc) {
{A B C D E F G H}
{I J K L M N O P}
{Q R S T U V W X}
{Y Z "" "" 123 BACK DEL DONE}
}
set keys(123) {
{"" "" 1 2 3 "" "" ""}
{"" "" 4 5 6 "" "" ""}
{"" "" 7 8 9 "" "" ""}
{"" "" "" 0 ABC BACK DEL DONE}
}

proc makeKeyboard { keySet } {
set keyboard [ttk::frame $::BASE.keyboard]
for {set row 0} {$row < 4} {incr row} {
grid rowconfigure $keyboard $row -weight 1 -uniform buttons -
minsize 50
for {set col 0} {$col < 8} {incr col} {
if {!$row} {
grid columnconfigure $keyboard $col -weight 1 -uniform
buttons -minsize 50
}
set key [lindex [lindex $keySet $row] $col]
grid [ttk::button $keyboard.b$row$col -takefocus 0 -style
Big.TButton -text $key -command [list keyAction $key]] \
-row $row -column $col -sticky snew
}
}

$::pw add $keyboard
}

makeKeyboard $keys(abc)

pack $BASE.client -side bottom -expand false -fill both -padx 1 -pady
1

wm title $ROOT ""
wm deiconify $ROOT
wm geometry . 800x600
update

fan...@telefonica.net

unread,
May 15, 2007, 4:02:50 AM5/15/07
to
> Currently the Telephone and Postcode label texts are
> centered in it's own row. How can I left justify this?

grid $l2.1 -row 0 -column 0 -sticky w -padx 2 -pady 2
grid $l2.tel_num -row 0 -column 1 -sticky e -padx 2 -pady 2


ttk::entry $l2.postcode -textvariable ::postcode
ttk::label $l2.2 -text Postcode

grid $l2.2 -row 1 -column 0 -sticky w -padx 2 -pady 2
grid $l2.postcode -row 1 -column 1 -sticky e -padx 2 -pady 2

> The listbox does not fill the width of the frame. How can I do this.
> The scrollbar is positioned somewhere to the "near" right. How can I
> make the scrollbar positioned to the right of the frame?

pack $l.lb -side left -fill both -expand 1
pack $l.sb -side left -fill y

> Finally, the scrollbar is two narrow. I think on an 8inch touch screen
> it will be harder to move the scrollbar. How can I make this wider?

scrollbar $l.sb -command "$l.lb yview" -width 50

It won't work with a tile scrollbar though.

Andres

Michael

unread,
May 15, 2007, 6:13:44 AM5/15/07
to

Thanks the left justify and expansion of the listbox is working well.

The adding of width to the scrollbar only adds a space between the
scrollbar and listbox. Is this because I'm using a tile frame?

M.

fan...@telefonica.net

unread,
May 15, 2007, 6:49:47 AM5/15/07
to

> The adding of width to the scrollbar only adds a space between the
> scrollbar and listbox. Is this because I'm using a tile frame?

No, I tried your script in Linux and it works.

It's probably because in windows tk uses native scrollbars which
can't be resized that way.

Andres


Michael

unread,
May 15, 2007, 8:19:00 AM5/15/07
to

Thanks. Is there a way to resize scrollbars for Windows XP?

I'll be porting over to Windows Mobile 5, so if anyone has done this
please let me know if it's possible for this platform.

M.

Bryan Oakley

unread,
May 15, 2007, 9:30:52 AM5/15/07
to

Try using the core Tk scrollbar rather than the tile one. At least on XP
you can configure the width to whatever you want. I don't know about
Windows Mobile.


--
Bryan Oakley
http://www.tclscripting.com

Michael

unread,
May 15, 2007, 1:15:04 PM5/15/07
to

Hi, am I not using the Tk scrollbar?

scrollbar $l.sb -command "$l.lb yview"

listbox $l.lb -yscroll "$l.sb set" -height 5

M.

Bryan Oakley

unread,
May 15, 2007, 1:34:34 PM5/15/07
to

Sorry. Yes, you are using it. It should be resizable. Are you reporting
that "scrollbar $l.sb -width xx" isn't working?

Try this as a really simple example:

scrollbar .vsb -orient vertical -width 100
pack .vsb -side right -fill y

On my machine I get a really wide scrollbar (though the size only seems
to take effect after I manually resize the window)

Michael

unread,
May 15, 2007, 1:54:33 PM5/15/07
to

Hi, yes this works if I resize the window. Is there a way to refresh
the winodw programatically. My program will fill the whole screen and
there will be no option for the user to resize.

M.

fan...@telefonica.net

unread,
May 16, 2007, 4:10:08 AM5/16/07
to

The only way I can see is to force the issue:

wm geometry . 799x600
update


wm geometry . 800x600
update

The user may see a flicker when the app starts up but it is no big
deal.

You could also report the bug for a better long term solution

http://sourceforge.net/tracker/?atid=112997&group_id=12997&func=browse

Andres

Chun

unread,
May 16, 2007, 5:44:20 AM5/16/07
to

Thanks. Works perfectly.

M.

0 new messages