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

Tile Button Size

10 views
Skip to first unread message

Michael

unread,
May 12, 2007, 5:53:57 PM5/12/07
to
Hello,

I'm trying to create a virtual keyboard for use on a touch screen
monitor. I'm using a grid 8x4 of ttk::button but at the moment the
buttons are too small. I need to make them 98x98 pixels. How can I do
this? I tried defining something below but it doesn't seem to work.
Any ideas?

style configure keyButtons -height 200 -width 200 -pady 2 -padx 2
ttk::button .a -text A -height 200
grid x .a

M.

Georgios Petasis

unread,
May 12, 2007, 6:33:28 PM5/12/07
to Michael
O/H Michael έγραψε:

The following code will ensure that all buttons are at least 98 pixels:

package require tile
for {set row 0} {$row < 4} {incr row} {
grid rowconfigure . $row -weight 1 -uniform buttons -minsize 98
for {set col 0} {$col < 8} {incr col} {
if {!$row} {
grid columnconfigure . $col -weight 1 -uniform buttons -minsize 98
}
grid [ttk::button .b$row$col -text "($row, $col)"] \
-row $row -column $col -sticky snew
}
}

George

Michael

unread,
May 13, 2007, 6:31:35 AM5/13/07
to

Thanks George. Your solution is working nicely. So I have:

variable TOP[ttk::frame .base]
pack $TOP -side top -expand true -fill both

set l [ttk::labelframe $pw.l -padding 1 -underline 1]
set l [ttk::labelframe $pw.l -padding 1 -underline 1]
$pw add $l -weight 1

ttk::entry $l.tel_num -textvariable ::tel_num -width 40
ttk::entry $l.postcode -textvariable ::postcode
ttk::entry $l.property_id -textvariable ::property_id
ttk::label $l.1 -text Telephone
ttk::label $l.2 -text No
ttk::label $l.3 -text Postcode
grid $l.1 $l.tel_num -sticky ew -padx 2 -pady 2
grid $l.2 $l.property_id -sticky ew -padx 2 -pady 2
grid $l.3 $l.postcode -sticky ew -padx 2 -pady 2

set keyboard [ttk::frame $::BASE.keyboard]


for {set row 0} {$row < 4} {incr row} {

grid rowconfigure $keyboard $row -weight 1 -uniform buttons -


minsize 98
for {set col 0} {$col < 8} {incr col} {
if {!$row} {

grid columnconfigure $keyboard $col -weight 1 -uniform buttons
-minsize 98
}
grid [ttk::button $keyboard.b$row$col -text "($row, $col)"] \
-row $row -column $col -sticky snew -command [list
keyBoardAction $row $col]
}
}

$pw add $keyboard

In my application I the user selects an entry field and then uses the
virtual keyboard to enter the text. Each time a button is pressed then
the focus moves to the button. How can I keep focus on the entry
field?

Also I want to be able to hide and unhide the virtual keyboard. It is
as straight forward as making the height of the panel containing the
keyboard much smaller?

My final problem is that I want to run on a PDA as well as a touch
screen monitor. Is there a way to get the maximum screen size in
pixels automatically?

M.

Georgios Petasis

unread,
May 13, 2007, 9:18:35 AM5/13/07
to Michael
O/H Michael έγραψε:

use -takefocus 0 when you create each button


>
> Also I want to be able to hide and unhide the virtual keyboard. It is
> as straight forward as making the height of the panel containing the
> keyboard much smaller?

Well it depends on your code. What widget is $pw?
In your case I will try to unmap the keyboard frame
(using pack/grid forget or similar...)
It is not a good idea to make it very small...
A better solution would have been the keyboard to be on a new toplevel
(without borders) that appears below/above the entry. When it is not
need it any more, you destroy it...

>
> My final problem is that I want to run on a PDA as well as a touch
> screen monitor. Is there a way to get the maximum screen size in
> pixels automatically?

winfo screenwidth .
winfo screenheight .

George

Michael

unread,
May 13, 2007, 7:32:36 PM5/13/07
to

Thanks George. I've taken your suggestion on destroying the panel for
when I change from letters to numbers and back again. I will use the
same technique for hiding and unhiding. Below is the updated code. The
focus tip you gave is working nicely. I added moving the cursor to the
right place with "icursor" and used the "focus" command to get the
widget name.

I am changing the input to a selection lists and have a question on
this but will start a new topic.

M.

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 -text $key -
command [list keyAction $key]] \


-row $row -column $col -sticky snew
}
}

$::pw add $keyboard
}

makeKeyboard $keys(abc)

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) != "\."} {
append ::$eVar $key
set pos [string length [set ::$eVar]]
if {$pos > -1} {
$Focus(Widget) icursor $pos
}
}
}
}
}

0 new messages