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

GUI with TCL(Pointwise) hide and show items in gridlayout

104 views
Skip to first unread message

Kim Skatun

unread,
May 13, 2013, 3:51:44 AM5/13/13
to
Hi
I am pretty new to TK and have some problem with hiding showing items in a gridlayout,

I basically have 4 choices driven by 2 checkboxes and dependent on this it shows some labels with an edit box connected to it.



I have 2 lines one upper and one lower. My gui is supposed to place points on these lines:

Choice 1: Both lines have equal spacing(1 edit box with label spacing)
Choice 2: Different spacing on upper and lower line (2 edit boxes with label upper and lower spacing)
choice 3: Spacing between pints is smaller towards the end of both lines(2 edit boxes spacing LE, spacing TE)
choice 4: Differnet at all 4 ends(4 edit boxes with labels Upper LE spacing, Upper TE spacing, Lower LE and Lower TE)




The problem is that I cant figure out how to show and hide the 4 different options.

Below is the creation code and the event code when the checkboxes are clicked.

Thanks for any tips.



#**********************************************************************************************************************
# Create Spacing Frame
set leSpacing 0.0001
set teSpacing 0.0001
set spacing 0.0001
set uSpacing 0.0001
set lpacing 0.0001
set leUSpacing 0.0001
set teUSpacing 0.0001
set leLSpacing 0.0001
set teLSpacing 0.0001

set symSpacingLETE 0
set symSpacingUL 1

# 0 spacing
# 1 uspacing
# 2 lspacing
# 3 leSpacing
# 4 teSpacing
# 5 leUSpacing
# 6 teUSpacing
# 7 leLSpacing
# 8 teLSpacing
set old {0 0 0 1 1 0 0 0 0}

grid [ttk::frame .spacing -padding "5 5 5 5"] -column 1 -row 0 -sticky nwes
grid [labelframe .spacing.lf3 -text "2. Define Spacing Conditions Parameters" -font {-slant italic} -padx 5 -pady 5]

grid [ttk::checkbutton .spacing.lf3.chkLETE -text "Symmetric LE/TE" -variable symSpacingLETE -command {
set old [spacingFrame $symSpacingLETE $symSpacingUL $labelWidth $entryWidth $old]
}] -column 0 -row 0 -sticky w

grid [ttk::checkbutton .spacing.lf3.chkUL -text "Symmetric upper/lower" -variable symSpacingUL -command {
set old [spacingFrame $symSpacingLETE $symSpacingUL $labelWidth $entryWidth $old]
}] -column 1 -row 0 -sticky w


grid [ttk::label .spacing.lf3.leSpacingL -text "Spacing toward LE" -width $labelWidth] -column 0 -row 1 -sticky w
grid [ttk::entry .spacing.lf3.leSpacingE -width $entryWidth -textvariable leSpacing] -column 1 -row 1 -sticky e

grid [ttk::label .spacing.lf3.teSpacingL -text "Spacing toward TE" -width $labelWidth] -column 0 -row 2 -sticky w
grid [ttk::entry .spacing.lf3.teSpacingE -width $entryWidth -textvariable teSpacing] -column 1 -row 2 -sticky e







# spacing GUI
#
proc spacingFrame {symSpacingLETE symSpacingUL labelWidth entryWidth old} {

set createI -1
set deleteI -1
set rowNumber 0

if {$symSpacingLETE == 1 && $symSpacingUL == 1} {
set new {1 0 0 0 0 0 0 0 0}
}

if {$symSpacingLETE == 1 && $symSpacingUL == 0} {
set new {0 1 1 0 0 0 0 0 0}
}

if {$symSpacingLETE == 0 && $symSpacingUL == 1} {
set new {0 0 0 1 1 0 0 0 0}
}

if {$symSpacingLETE == 0 && $symSpacingUL == 0} {
set new {0 0 0 0 0 1 1 1 1}
}

puts $old

for {set i 0} {$i < [llength $new]} {incr i} {


if {[expr {[lindex $new $i] - [lindex $old $i] }] ==1} {
set createI $i
set rowNumber [expr {$rowNumber+1}]
}

if {[expr {[lindex $new $i] - [lindex $old $i] }] ==-1} {
set deleteI $i
}


puts "Create $createI at $i"
puts "Delete $deleteI at $i"

# 0 spacing
# 1 uspacing
# 2 lspacing
# 3 leSpacing
# 4 teSpacing
# 5 leUSpacing
# 6 teUSpacing
# 7 leLSpacing
# 8 teLSpacing

if {$deleteI == 0} {
grid forget .spacing.lf3.leSpacingL
grid forget .spacing.lf3.leSpacingE
}
if {$deleteI == 1} {
grid forget .spacing.lf3.uSpacingL
grid forget .spacing.lf3.uSpacingE
}
if {$deleteI == 2} {
grid forget .spacing.lf3.lSpacingL
grid forget .spacing.lf3.lSpacingE
}
if {$deleteI == 3} {
grid forget .spacing.lf3.leSpacingL
grid forget .spacing.lf3.leSpacingE
}
if {$deleteI == 4} {
grid forget .spacing.lf3.teSpacingL
grid forget .spacing.lf3.teSpacingE
}
if {$deleteI == 5} {
grid forget .spacing.lf3.leUSpacingL
grid forget .spacing.lf3.leUSpacingE
}
if {$deleteI == 6} {
grid forget .spacing.lf3.teUSpacingL
grid forget .spacing.lf3.teUSpacingE
}
if {$deleteI == 7} {
grid forget .spacing.lf3.leLSpacingL
grid forget .spacing.lf3.teLSpacingE
}
if {$deleteI == 8} {
grid forget .spacing.lf3.teLSpacingL
grid forget .spacing.lf3.teLSpacingE

}


# 0 spacing
# 1 uspacing
# 2 lspacing
# 3 leSpacing
# 4 teSpacing
# 5 leUSpacing
# 6 teUSpacing
# 7 leLSpacing
# 8 teLSpacing



if {$createI == 0} {
# if {[info exists .spacing.lf3.spacingL]} {
# pack .spacing.lf3.spacingL
# }
# else {
grid [ttk::label .spacing.lf3.spacingL -text "Spacing " -width $labelWidth] -column 0 -row $rowNumber -sticky w
grid [ttk::entry .spacing.lf3.spacingE -width $entryWidth -textvariable spacing] -column 1 -row $rowNumber -sticky e
# }
}
if {$createI == 1} {
grid [ttk::label .spacing.lf3.uSpacingL -text "Spacing upper" -width $labelWidth] -column 0 -row $rowNumber -sticky w
grid [ttk::entry .spacing.lf3.uSpacingE -width $entryWidth -textvariable uSpacing] -column 1 -row $rowNumber -sticky e
}
if {$createI == 2} {
grid [ttk::label .spacing.lf3.lSpacingL -text "Spacing lower" -width $labelWidth] -column 0 -row $rowNumber -sticky w
grid [ttk::entry .spacing.lf3.lSpacingE -width $entryWidth -textvariable lSpacing] -column 1 -row $rowNumber -sticky e
}
if {$createI == 3} {
grid [ttk::label .spacing.lf3.leSpacingL -text "Spacing toward LE" -width $labelWidth] -column 0 -row $rowNumber -sticky w
grid [ttk::entry .spacing.lf3.leSpacingE -width $entryWidth -textvariable leSpacing] -column 1 -row $rowNumber -sticky e
}
if {$createI == 4} {
grid [ttk::label .spacing.lf3.teSpacingL -text "Spacing toward TE" -width $labelWidth] -column 0 -row $rowNumber -sticky w
grid [ttk::entry .spacing.lf3.teSpacingE -width $entryWidth -textvariable teSpacing] -column 1 -row $rowNumber -sticky e
}
if {$createI == 5} {
grid [ttk::label .spacing.lf3.leUSpacingL -text "Spacing toward upper LE" -width $labelWidth] -column 0 -row $rowNumber -sticky w
grid [ttk::entry .spacing.lf3.leUSpacingE -width $entryWidth -textvariable leUSpacing] -column 1 -row $rowNumber -sticky e
}
if {$createI == 6} {
grid [ttk::label .spacing.lf3.teUSpacingL -text "Spacing toward upper TE" -width $labelWidth] -column 0 -row $rowNumber -sticky w
grid [ttk::entry .spacing.lf3.teUSpacingE -width $entryWidth -textvariable teUSpacing] -column 1 -row $rowNumber -sticky e
}
if {$createI == 7} {
grid [ttk::label .spacing.lf3.leLSpacingL -text "Spacing toward lower LE" -width $labelWidth] -column 0 -row $rowNumber -sticky w
grid [ttk::entry .spacing.lf3.leLSpacingE -width $entryWidth -textvariable leLSpacing] -column 1 -row $rowNumber -sticky e
}
if {$createI == 8} {
grid [ttk::label .spacing.lf3.teLSpacingL -text "Spacing toward lower TE" -width $labelWidth] -column 0 -row $rowNumber -sticky w
grid [ttk::entry .spacing.lf3.teLSpacingE -width $entryWidth -textvariable teLSpacing] -column 1 -row $rowNumber -sticky e
}




set createI -1
set deleteI -1

}


return $new
}

DrS

unread,
May 13, 2013, 7:18:40 AM5/13/13
to
On 5/13/2013 3:51 AM, Kim Skatun wrote:
>
> The problem is that I cant figure out how to show and hide the 4 different options.
>
> Below is the creation code and the event code when the checkboxes are clicked.
>
> Thanks for any tips.
>

I haven't looked at the code but it sounds like [grid hide] command is
what you are after. Use it when you need to hide stuff and then when
you need to show it again, use the [grid config] command as you are
doing now.

DrS

DrS

unread,
May 13, 2013, 7:26:58 AM5/13/13
to
There was a type above: it should be [grid forget]. And I see that you
are already using it but in a slightly more verbose way than it needs to
be.

Here is a suggestion: put a variable trace on each of the two options.
When they change, use grid forget/config commands to hide and show the
entry widgets as you need.

The command you need is: "trace add variable ..."


DrS



Kim Skatun

unread,
May 13, 2013, 10:47:09 AM5/13/13
to
Do you create all entries at init even if in most cases you dont need them? And then forget them and create the ones you need as default?

The problem is that i get an error saying it already exist if i first show it then hide(forget) it and then show it again.

DrS

unread,
May 13, 2013, 12:34:19 PM5/13/13
to
On 5/13/2013 10:47 AM, Kim Skatun wrote:
> Do you create all entries at init even if in most cases you dont need them? And then forget them and
> create the ones you need as default?
>

You could just create all of the widgets once at the beginning; and
using grid, display or hide them as needed. If you prefer, instead of
hiding and displaying, you can destroy and recreate them as well. I
guess it depends on how much effort you have already put into it.


> The problem is that i get an error saying it already exist if i first show it then hide(forget) it
> and then show it again.
>

If you are almost there, there may be no need to switch strategies. You
can simply put a check to see if the widget already exists like this:

if {[winfo exists $xyz]} {
# just display or hide it here
} else {
# here, create it from scratch and display it
}


DrS


Uwe Klein

unread,
May 13, 2013, 1:06:00 PM5/13/13
to
the blt::table gridding thing allowed to
configure row height and column width to zero ( i.e. invisible )

Then you could grid all widgets into their respective places
add a frame that covers all relevant rows and columns and
just raise the widget group that you want to show.
Actually raise the frame first and then all visible items.

see:
frame .f
entry .e -textvariable xyz
label .l -textvariable xyz

# this fits all widgets into the same cell:
grid .f -row 0 -column 0 -sticky nswe
grid .l -row 0 -column 0 -sticky nswe
grid .e -row 0 -column 0 -sticky nswe

# raise entry:
proc raise_entry {} {
raise .f
raise .e
}

# raise alternate
proc raise_label {} {
raise .f
raise .l
}

uwe

tomás zerolo

unread,
May 13, 2013, 3:40:22 PM5/13/13
to
Kim Skatun <ska...@gmail.com> writes:

> Do you create all entries at init even if in most cases you dont need them? And then forget them and create the ones you need as default?
>
> The problem is that i get an error saying it already exist if i first show it then hide(forget) it and then show it again.

I think I know what's happening. Quoting from your code above, that's
what you do when "hiding" an entry:

if {$deleteI == 1} {
grid forget .spacing.lf3.uSpacingL
grid forget .spacing.lf3.uSpacingE
}

and when "showing" it:

if {$createI == 1} {
grid [ttk::label .spacing.lf3.uSpacingL -text "Spacing upper" -width $labelWidth] -column 0 -row $rowNumber -sticky w
grid [ttk::entry .spacing.lf3.uSpacingE -width $entryWidth -textvariable uSpacing] -column 1 -row $rowNumber -sticky e
}

Note that grid [ttk::label ...] -column 0 ... is trying to re-create the
widget. Once it's created,

grid .spacing.lf3.uSpacingL -column 0 -row $rowNumber -sticky w

should be sufficient. You'll have to arrange for the widget to be
created at the first try, of course. May be by pre-creating them all, or
by doing some "lazy creation". Just ask if you get stuck.

Regards
-- tomás
0 new messages