Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

focus and insert between frames 1

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

I have a series of frames on top of each other, each frame contains a radiobutton and a button. I want to be able to click on any of them and add a new one before or after or simply delete one frame interactively. In order to do this I need a way to make a specific frame to be "selected" when I click on it (in that case a line should appear around the frame),what is the best way to do this? When three frames are already packed on top of each other, how can I insert a new frame in between the second and third frame for instance (frame number two should be "selected")?


Thanks for your help!



 
It's possible to do what you're asking in pure Tcl. There are several different Tcl programming techniques I'll be demonstrating here. Rather than describe them all in depth beforehand, I'll just include some code comments about them as I go along.

Code:
##################################
# FrameSelect
# 
# Called by a binding to select a frame.
##################################

proc FrameSelect {w} {
  global selected

  # If the user clicked on a child widget
  # rather than its parent frame, cycle up
  # to the parent frame. Note that this
  # simple algorithm *doesn't* allow for
  # another frame to be nested in our
  # containing frame. It also relies on you
  # not changing the frame's class to
  # anything other than "Frame" to work
  # properly.

  while {([winfo class $w] != "Frame")
         && ("$w" != ".")} {

    set w [winfo parent $w]
  }

  # "De-select" whatever is currently
  # selected. This also handles "toggling"
  # an already selected frame by clicking on
  # it again.

  if {[info exists selected(current)]} {
    $selected(current) configure       -relief $selected(relief)
  }

  if {[info exists selected(current)]
       && ($selected(current) == $w)} {

    # The user clicked on the frame already
    # selected. Simply "de-select" the frame
    # and return.

    unset selected(current)
    return

  } else {

    # Highlight the selected frame by
    # changing its border to groove. To be
    # visible, the frame must have its
    # border width (-bd) set to a value
    # greater than 2.

    set selected(relief) [$w cget -relief]
    set selected(current) $w

    $w configure -relief groove
  }
}

# Create a symbolic bindtag called
# "selectable", that invokes our FrameSelect
# procedure in response to a left-click.

bind selectable <ButtonPress-1> {
  FrameSelect %W
}

# Initialize a counter to help us create
# unique frame names on demand.

set frameCounter 0

##################################
# InsertFrame
# 
# Create a frame on demand. If another frame
# is selected, the new frame is packed
# before the selected frame; otherwise, the
# new frame is packed after all existing
# frames.
##################################

proc InsertFrame {} {
  global selected
  global frameCounter

  set i [incr frameCounter]

  frame .f$i -bd 2

  radiobutton .f$i.r -text &quot;Option $i&quot;     -variable x -value $i
  button .f$i.b -text &quot;Waffle&quot;

  # Insert our &quot;selectable&quot; bindtag at the
  # beginning of the bindtag path for the
  # frame.

  bindtags .f$i [linsert [bindtags .f$i]     0 selectable]

  # Uncomment the following lines if you
  # want the frame toggling binding active
  # for the contents of the frame as well.

  # bindtags .f$i.r [linsert       [bindtags .f$i.r] 0 selectable]
  # bindtags .f$i.b [linsert       [bindtags .f$i.b] 0 selectable]

  pack .f$i.r -padx 2 -pady 2 -anchor w
  pack .f$i.b -padx 2 -pady 2

  if {[info exists selected(current)]} {

    # If a frame is selected, insert the new
    # frame in front of the selected one in
    # the packing order.

    pack .f$i -before $selected(current)       -padx 2 -pady 2 -fill x

  } else {

    # If no frame is selected, pack the new
    # frame after all other frames.

    pack .f$i -padx 2 -pady 2 -fill x
  }
}

##################################
# DeleteFrame
# 
# Delete the currently selected frame. If no
# frame is selected, nothing happens.
##################################

proc DeleteFrame {} {
  global selected
  if {[info exists selected(current)]} {
    destroy $selected(current)
    unset selected(current)
  }
}

# Define virtual events, which allows us to
# use mutiple bindings to perform the same
# task.

event add <<Insert>>   <Control-KeyPress-a> <KeyPress-Insert>

event add <<Delete>>   <Control-KeyPress-d> <KeyPress-Delete>

# Bind to the toplevel window, so that these
# bindings are active no matter which widget
# has focus.

bind . <<Insert>> InsertFrame
bind . <<Delete>> DeleteFrame

Another possibility, which will probably be simpler, would be to use an extension like TkTable to manage your collection of frames. TkTable provides a spreadsheet-like container for manipulating text and widgets. I suspect it would be a lot easier for TkTable to manage all the selection, insertion, and deletion of frames than to cobble it together with Tcl code like I did above. you can find outmore about TkTable on the Tcl'ers Wiki ( on the page &quot;Tktable,&quot; - Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
thank you very much Ken. This works fine, however, I have a few more questions:

1) I don't understand what this does:
# Insert our &quot;selectable&quot; bindtag at the
# beginning of the bindtag path for the
# frame.

bindtags .f$i [linsert [bindtags .f$i] 0 selectable]

# Uncomment the following lines if you
# want the frame toggling binding active
# for the contents of the frame as well.

# bindtags .f$i.r [linsert [bindtags .f$i.r] 0 selectable]
# bindtags .f$i.b [linsert [bindtags .f$i.b] 0 selectable]


2) I had to add this at the beginning of my script for the selection to work
bind . <ButtonPress-1> {
FrameSelect %W
}

What does this do?
# Create a symbolic bindtag called
# &quot;selectable&quot;, that invokes our FrameSelect
# procedure in response to a left-click.

bind selectable <ButtonPress-1> {
FrameSelect %W
}


3)
The problem I have now is that my frame is not scrollable. I found an old post of yours explaining how to do this. I can't get it to work, what am I doing wrong (see code posted below)?

#!/usr/local/bin/wish
#exec wish &quot;$0&quot; &quot;$@&quot;
#-----------------------------------------------------------------------------
###############
# ZMAP MACRO BUILDER
#
# AUTHOR: Fabien Coutel
#
# Last Modified : Wed Sep 25 13:15:39 BST 2002
##################################################
# set global variables


##############################

frame .top -borderwidth 2
pack .top -fill x
#
# LGC LOGO
#
set i [image create photo -file lgc_logo.gif ]
#set logo [checkbutton .top.but -image $i -selectcolor SeaGreen1]
#pack .top.but -expand yes
#
#MENUS
#

#
#MENUS
#

menu .top.menuBar -tearoff 0
set f .top.menuBar.file
set fc .top.menuBar.func
set h .top.menuBar.help
set edit .top.menuBar.edit
#logo
.top.menuBar add command -image $i -command {}
#File menu
.top.menuBar add cascade -menu $f -label &quot;File&quot; -font {Helvetica 14 bold} -underline 0
menu $f -tearoff 1
$f add command -label &quot;New&quot; -font {Helvetica 12 bold} -underline 0 -command {}
$f add command -label &quot;Open&quot; -font {Helvetica 12 bold} -underline 0 -command {}
$f add command -label &quot;Save&quot; -font {Helvetica 12 bold} -underline 0 -command {}
$f add separator
$f add command -label &quot;Exit&quot; -font {Helvetica 12 bold} -underline 1 -command {exit} -accelerator &quot;Meta-q&quot;

#Edit
.top.menuBar add cascade -menu $edit -label &quot;Edit&quot; -font {Helvetica 14 bold} -underline 0
menu $edit -tearoff 1
$edit add command -label &quot;Add before&quot; -font {Helvetica 12 bold} -underline 0 -command {}
$edit add command -label &quot;Add after&quot; -font {Helvetica 12 bold} -underline 0 -command {}
$edit add command -label &quot;Delete&quot; -font {Helvetica 12 bold} -underline 0 -command {}

#Functions
.top.menuBar add cascade -menu $fc -label &quot;Functions&quot; -font {Helvetica 14 bold} -underline 0
menu $fc -tearoff 1
$fc add command -label &quot;Import&quot; -font {Helvetica 12 bold} -underline 0 -command {}

#help menu
.top.menuBar add cascade -menu $h -label &quot;Help&quot; -font {Helvetica 14 bold} -underline 0
menu $h -tearoff 1
$h add command -label &quot;About..&quot; -font {Helvetica 12 bold} -command {About} -underline 0

global f h fc edit


# bind accelerator keys
bind . <Meta-q> {exit}
# for frame select
bind . <ButtonPress-1> {
FrameSelect %W
}

. configure -menu .top.menuBar

# main window
#
wm title . &quot;ZMAP MACRO BUILDER&quot;
wm geometry . 80x20
####
#frames
# for buttons
frame .btfr -borderwidth 10
pack .btfr -side top -fill x -expand 0

# create canvas to put flows
# Use Canvas to implement scrollable frame
canvas .c -height 100 -width 50 -yscrollcommand {.sb set}
scrollbar .sb -orient vertical -command {.c yview}
# frame that holds flows
frame .c.fcfr -borderwidth 2 -relief sunken

# Tell the canvas to display the frame, anchoring the
# upper-left hand corner of the frame in the upper-left
# hand corner of the canvas

#.c create window 0 0 -anchor nw -window .c.fcfr

# Use grid to display the canvas, the scrollbar, and the
# close button in the toplevel window. Handle resizing properly.
grid .c -row 0 -column 0 -sticky nsew -pady 4 -padx 2
grid .sb -row 0 -column 1 -sticky ns -pady 4 -padx 2
grid columnconfigure . 0 -weight 1
grid rowconfigure . 0 -weight 1

# Detect <Configure> events on the frame to detect when
# it is first displayed and any time is is resized.
# In either case, recompute the visible bounds of the
# canvas and update its -scrollregion attribute.

bind .c.fcfr <Configure> {
.c configure -scrollregion [.c bbox all]
}

##
###
#function frame
set incfr 0
# Initialize a counter to help us create
# unique frame names on demand.
set frameCounter [incr incfr]
global incfr frameCounter


#
# Action Buttons
#
set but [button .btfr.run -background #88ff88 -activebackground #88ff88 -text &quot;Run&quot; -command Run]
button .btfr.quit -background #ffbbbb -activebackground #ffbbbb -text &quot;Quit&quot; -command exit
pack .btfr.run -side left -padx 100
pack .btfr.quit -side left


#
# Lower frame holds text output
#

frame .logfr
set log [text .logfr.log -width 50 -height 5 -borderwidth 3 -relief sunken -setgrid true -yscrollcommand {.logfr.scroll set} -font {courier 9}]
scrollbar .logfr.scroll -command {.logfr.log yview}
pack .logfr.scroll -side right -fill y
pack .logfr.log -side left -fill both -expand true
pack .logfr -side top -fill both -expand true

###########
# FUNCTIONS
############


###
# MAKE PROCESS FRAME
###
proc MakeFrame {w} {
# make frame
frame $w -borderwidth 4
pack $w -side top -fill x
#checkbutton
checkbutton $w.cb -text &quot;Empty &quot; -variable dummy -command {} -padx 10
#button
button $w.b -text &quot;Parameters...&quot; -width 10 -command {} -padx 20
pack $w.cb $w.b -padx 2 -pady 2 -side left
}

##################################
# FrameSelect
#
# Called by a binding to select a frame.
##################################

proc FrameSelect {w} {
global selected

puts &quot;in FrameSelect&quot;

# If the user clicked on a child widget
# rather than its parent frame, cycle up
# to the parent frame. Note that this
# simple algorithm *doesn't* allow for
# another frame to be nested in our
# containing frame. It also relies on you
# not changing the frame's class to
# anything other than &quot;Frame&quot; to work
# properly.

while {([winfo class $w] != &quot;Frame&quot;)
&& (&quot;$w&quot; != &quot;.&quot;)} {

set w [winfo parent $w]
}

# &quot;De-select&quot; whatever is currently
# selected. This also handles &quot;toggling&quot;
# an already selected frame by clicking on
# it again.

if {[info exists selected(current)]} {
$selected(current) configure -relief $selected(relief)
}

#if {[info exists selected(current)]
#&& ($selected(current) == $w)} {

# The user clicked on the frame already
# selected. Simply &quot;de-select&quot; the frame
# and return.

#unset selected(current)
#return

#} else {

# Highlight the selected frame by
# changing its border to groove. To be
# visible, the frame must have its
# border width (-bd) set to a value
# greater than 2.

set selected(relief) [$w cget -relief]
set selected(current) $w

$w configure -relief groove
#}
}

# Create a symbolic bindtag called
# &quot;selectable&quot;, that invokes our FrameSelect
# procedure in response to a left-click.

bind selectable <ButtonPress-1> {
FrameSelect %W
}


##################################
# InsertFrame
#
# Create a frame on demand. If another frame
# is selected, the new frame is packed
# before the selected frame; otherwise, the
# new frame is packed after all existing
# frames.
##################################

proc InsertFrame {} {
global selected
global frameCounter

set i [incr frameCounter]

set f .fcfr.fr$i
MakeFrame $f

# Insert our &quot;selectable&quot; bindtag at the
# beginning of the bindtag path for the
# frame.

bindtags $f [linsert [bindtags $f] 0 selectable]

# Uncomment the following lines if you
# want the frame toggling binding active
# for the contents of the frame as well.

# bindtags $f.cb [linsert [bindtags $f.cb] 0 selectable]
# bindtags $f.b [linsert [bindtags $f.b] 0 selectable]

#pack $f.cb -padx 2 -pady 2 -anchor w
#pack $f.b -padx 2 -pady 2

if {[info exists selected(current)]} {

# If a frame is selected, insert the new
# frame in front of the selected one in
# the packing order.

pack $f -before $selected(current) -padx 2 -pady 2 -fill x

} else {

# If no frame is selected, pack the new
# frame after all other frames.

pack $f -padx 2 -pady 2 -fill x
}
}

##################################
# DeleteFrame
#
# Delete the currently selected frame. If no
# frame is selected, nothing happens.
##################################

proc DeleteFrame {} {
global selected
if {[info exists selected(current)]} {
destroy $selected(current)
unset selected(current)
}
}

# Define virtual events, which allows us to
# use mutiple bindings to perform the same
# task.

event add <<Insert>> <Control-KeyPress-a> <KeyPress-Insert>

event add <<Delete>> <Control-KeyPress-d> <KeyPress-Delete>

# Bind to the toplevel window, so that these
# bindings are active no matter which widget
# has focus.

bind . <<Insert>> InsertFrame
bind . <<Delete>> DeleteFrame


###### MAIN #########
#set first frame (default)
set fu .c.fcfr.fr$incfr
#display first frame (default)
MakeFrame $fu

Thanks so much!
 
In response to your first two questions, what I'm doing is to create a symbolic binding tag with a binding for <ButtonPress-1> events, and then inserting that binding tag into the bindtag path of each special frame I create, so that it's the first place the frame looks for bindings to execute. I describe this technique in detail in thread287-211083, &quot;how to forget bindings in text widget.&quot;

I'm not sure exactly why you had to create the <ButtonPress-1> binding on &quot;.&quot; to get your frame selection to work properly; that was the whole point of creating the symbolic bindtag and applying it to only those frames I wanted to be selectable. However, I suspect it might be connected with a bug I spotted in your program, which is also probably causing the problem with the scrolling.

In your InsertFrame procedure, you have the following code:

[tt]set f .fcfr.fr$i
MakeFrame $f[/tt]

However, if I'm interpreting your program correctly, that's not the correct name for the &quot;scrollable frame&quot; you created earlier. That was:

[tt]frame .c.fcfr -borderwidth 2 -relief sunken[/tt]

Therefore, to put the other frames you create within the scrollable frame, you have to give them names that indicate that they're children of the scrollable frame:

[tt]set f .c.fcfr.fr$i
MakeFrame $f[/tt]

Also, I noticed that you commented out the line:

Code:
#.c create window 0 0 -anchor nw -window .c.fcfr

Unless this was some sort of cut-and-paste typo, I don't see how your program will work correctly. This line actually displays the scrollable frame within the canvas widget. When using a canvas widget as a geometry manager, as we're doing here, you display direct children of the canvas using the create window operation, not pack or grid. - Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
thanks for the link Ken this will help.

Regarding the other points I had commented this line out for testing I have also fixed the bug you mentioned as well with the wrong name for the frame but this does not make any difference. I noticed that I comment out my menu frame (frame .top -borderwidth 2
pack .top -fill x
)
buttons & log frames then the canvas appears. I have tried without -fill x to no avail. Can I mix normal frames with canvas?

Thanks!
 
I think I found why nothing appeared. I need to create a frame to put the canvas on and then create a frame inside the canvas. The problem I have now is that the scrollbar keeps growing when I add item, how can I stop this. here is the new code below.

Thanks!

#!/usr/local/bin/wish
#exec wish &quot;$0&quot; &quot;$@&quot;
#-----------------------------------------------------------------------------
###############
# ZMAP MACRO BUILDER
#
# AUTHOR: Fabien Coutel
#
# Last Modified : Wed Sep 25 13:15:39 BST 2002
##################################################
# set global variables


##############################
frame .top -borderwidth 2
pack .top -fill x
#
# LGC LOGO
#
set i [image create photo -file lgc_logo.gif ]
#set logo [checkbutton .top.but -image $i -selectcolor SeaGreen1]
#pack .top.but -expand yes
#
#MENUS
#

#
#MENUS
#

menu .top.menuBar -tearoff 0
set f .top.menuBar.file
set fc .top.menuBar.func
set h .top.menuBar.help
set edit .top.menuBar.edit
#logo
.top.menuBar add command -image $i -command {}
#File menu
.top.menuBar add cascade -menu $f -label &quot;File&quot; -font {Helvetica 14 bold} -underline 0
menu $f -tearoff 1
$f add command -label &quot;New&quot; -font {Helvetica 12 bold} -underline 0 -command {}
$f add command -label &quot;Open&quot; -font {Helvetica 12 bold} -underline 0 -command {}
$f add command -label &quot;Save&quot; -font {Helvetica 12 bold} -underline 0 -command {}
$f add separator
$f add command -label &quot;Exit&quot; -font {Helvetica 12 bold} -underline 1 -command {exit} -accelerator &quot;Meta-q&quot;

#Edit
.top.menuBar add cascade -menu $edit -label &quot;Edit&quot; -font {Helvetica 14 bold} -underline 0
menu $edit -tearoff 1
$edit add command -label &quot;Add before&quot; -font {Helvetica 12 bold} -underline 0 -command {}
$edit add command -label &quot;Add after&quot; -font {Helvetica 12 bold} -underline 0 -command {}
$edit add command -label &quot;Delete&quot; -font {Helvetica 12 bold} -underline 0 -command {}

#Functions
.top.menuBar add cascade -menu $fc -label &quot;Functions&quot; -font {Helvetica 14 bold} -underline 0
menu $fc -tearoff 1
$fc add command -label &quot;Import&quot; -font {Helvetica 12 bold} -underline 0 -command {}

#help menu
.top.menuBar add cascade -menu $h -label &quot;Help&quot; -font {Helvetica 14 bold} -underline 0
menu $h -tearoff 1
$h add command -label &quot;About..&quot; -font {Helvetica 12 bold} -command {About} -underline 0

global f h fc edit


# bind accelerator keys
bind . <Meta-q> {exit}
# for frame select
bind . <ButtonPress-1> {
FrameSelect %W
}

. configure -menu .top.menuBar

# main window
#
wm title . &quot;ZMAP MACRO BUILDER&quot;
wm geometry . 600x400
####

frame .wid -borderwidth 10 -relief sunken

# create canvas to put flows
# Use Canvas to implement scrollable frame
canvas .wid.c -height 60 -width 10 -yscrollcommand {.wid.sb set}
scrollbar .wid.sb -orient vertical -command {.wid.c yview}
# frame that holds flows
frame .wid.c.fcfr -borderwidth 2 -relief sunken

# Tell the canvas to display the frame, anchoring the
# upper-left hand corner of the frame in the upper-left
# hand corner of the canvas

.wid.c create window 0 0 -anchor nw -window .wid.c.fcfr

# Use grid to display the canvas, the scrollbar, and the
# close button in the toplevel window. Handle resizing properly.
grid .wid.c -row 0 -column 0 -sticky nsew -pady 4 -padx 2
grid .wid.sb -row 0 -column 1 -sticky ns -pady 4 -padx 2
grid columnconfigure . 0 -weight 1
grid rowconfigure . 0 -weight 1

# Detect <Configure> events on the frame to detect when
# it is first displayed and any time is is resized.
# In either case, recompute the visible bounds of the
# canvas and update its -scrollregion attribute.

bind .wid.c.fcfr <Configure> {
.wid.c configure -scrollregion [.wid.c bbox all]

}

##
###
#function frame
set incfr 0
# Initialize a counter to help us create
# unique frame names on demand.
set frameCounter [incr incfr]
global incfr frameCounter

pack .wid -fill x
#frames
# for buttons
frame .btfr -borderwidth 10
pack .btfr -fill x

#
# Action Buttons
#

set but [button .btfr.run -background #88ff88 -activebackground #88ff88 -text &quot;Run&quot; -command Run]
button .btfr.quit -background #ffbbbb -activebackground #ffbbbb -text &quot;Quit&quot; -command exit
pack .btfr.run -side left -padx 100
pack .btfr.quit -side left


#
# Lower frame holds text output
#

#frame .logfr
#set log [text .logfr.log -width 50 -height 5 # -borderwidth 3 -relief sunken -setgrid true # -yscrollcommand {.logfr.scroll set} -font {courier 9}]
#scrollbar .logfr.scroll -command {.logfr.log yview}
#pack .logfr.scroll -side right -fill y
#pack .logfr.log -side left -fill both -expand true
#pack .logfr -side top -fill both -expand true

###########
# FUNCTIONS
############


###
# MAKE PROCESS FRAME
###
proc MakeFrame {w} {
# make frame
frame $w -borderwidth 4
pack $w -side top -fill x
#checkbutton
checkbutton $w.cb -text &quot;Empty &quot; -variable dummy -command {} -padx 10
#button
button $w.b -text &quot;Parameters...&quot; -width 10 -command {} -padx 20
pack $w.cb $w.b -padx 2 -pady 2 -side left
}

##################################
# FrameSelect
#
# Called by a binding to select a frame.
##################################

proc FrameSelect {w} {
global selected

puts &quot;in FrameSelect&quot;

# If the user clicked on a child widget
# rather than its parent frame, cycle up
# to the parent frame. Note that this
# simple algorithm *doesn't* allow for
# another frame to be nested in our
# containing frame. It also relies on you
# not changing the frame's class to
# anything other than &quot;Frame&quot; to work
# properly.

while {([winfo class $w] != &quot;Frame&quot;)
&& (&quot;$w&quot; != &quot;.&quot;)} {

set w [winfo parent $w]
}

# &quot;De-select&quot; whatever is currently
# selected. This also handles &quot;toggling&quot;
# an already selected frame by clicking on
# it again.

if {[info exists selected(current)]} {
$selected(current) configure -relief $selected(relief)
}

#if {[info exists selected(current)]
#&& ($selected(current) == $w)} {

# The user clicked on the frame already
# selected. Simply &quot;de-select&quot; the frame
# and return.

#unset selected(current)
#return

#} else {

# Highlight the selected frame by
# changing its border to groove. To be
# visible, the frame must have its
# border width (-bd) set to a value
# greater than 2.

set selected(relief) [$w cget -relief]
set selected(current) $w

$w configure -relief groove
#}
}

# Create a symbolic bindtag called
# &quot;selectable&quot;, that invokes our FrameSelect
# procedure in response to a left-click.

bind selectable <ButtonPress-1> {
FrameSelect %W
}


##################################
# InsertFrame
#
# Create a frame on demand. If another frame
# is selected, the new frame is packed
# before the selected frame; otherwise, the
# new frame is packed after all existing
# frames.
##################################

proc InsertFrame {} {
global selected
global frameCounter

set i [incr frameCounter]

set f .wid.c.fcfr$i
MakeFrame $f

# Insert our &quot;selectable&quot; bindtag at the
# beginning of the bindtag path for the
# frame.

bindtags $f [linsert [bindtags $f] 0 selectable]

# Uncomment the following lines if you
# want the frame toggling binding active
# for the contents of the frame as well.

# bindtags $f.cb [linsert [bindtags $f.cb] 0 selectable]
# bindtags $f.b [linsert [bindtags $f.b] 0 selectable]

pack $f.cb -padx 2 -pady 2 -anchor w
pack $f.b -padx 2 -pady 2

if {[info exists selected(current)]} {

# If a frame is selected, insert the new
# frame in front of the selected one in
# the packing order.

pack $f -before $selected(current) -padx 2 -pady 2 -fill x

} else {

# If no frame is selected, pack the new
# frame after all other frames.

pack $f -padx 2 -pady 2 -fill x
}
}

##################################
# DeleteFrame
#
# Delete the currently selected frame. If no
# frame is selected, nothing happens.
##################################

proc DeleteFrame {} {
global selected
if {[info exists selected(current)]} {
destroy $selected(current)
unset selected(current)
}
}

# Define virtual events, which allows us to
# use mutiple bindings to perform the same
# task.

event add <<Insert>> <Control-KeyPress-a> <KeyPress-Insert>

event add <<Delete>> <Control-KeyPress-d> <KeyPress-Delete>

# Bind to the toplevel window, so that these
# bindings are active no matter which widget
# has focus.

bind . <<Insert>> InsertFrame
bind . <<Delete>> DeleteFrame


###### MAIN #########
#set first frame (default)
set fu .wid.c.fcfr$incfr
#display first frame (default)
MakeFrame $fu

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top