You are here

vtcl 로 작성한 기본 frame에서 "add" button을 누르면 entry 가 추가 되고, "del" button을 누르면 삭제 되는 방법 부탁드립니다.

vtcl 사이트 http://vtcl.sourceforge.net

vtcl 로 작성한 기본 frame에서 "add" button을 누르면 entry 가 추가 되고, "del" button을
누르면 entry 가 삭제 되는 프로그램을 작성하고 싶은데,

button command 에 entry 변수(ex> $top.ent53 ) 를 집어 넣으면, entry 변수를 인식하지 못합니다.
scope 문제 인것 같은데 여기 scope 관련 강의를 보고 해봐도 잘 되지가 않습니다.
거의 몇일째 사경을 헤메고 있습니다. ㅠㅠ

아래 source code는 vtcl 에서 gneration 한 코드 입니다.
실행 해보시면 add button 한개 del 버튼 한개 default entry 한개가 나옵니다.
여기에서 add 를 누르면 entry 추가 , del 을 누르면 entry 삭제를 하고 싶습니다.
그리고 추가된 entry 변수를 어떻게 access 해야 되는 지도 알고 싶습니다.

vtcl 에서 generation 된 코드가 말도 안되게 너무 복잡해서 초보인 저에게는 너무나 벅차네요.

========================================================

#!/bin/sh
# the next line restarts using wish\
exec wish "$0" "$@"

if {![info exists vTcl(sourcing)]} {

package require Tk
switch $tcl_platform(platform) {
windows {
option add *Button.padY 0
}
default {
option add *Scrollbar.width 10
option add *Scrollbar.highlightThickness 0
option add *Scrollbar.elementBorderWidth 2
option add *Scrollbar.borderWidth 2
}
}

}

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

# Visual Tcl v1.60 Project
#

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

# VTCL LIBRARY PROCEDURES
#

if {![info exists vTcl(sourcing)]} {
####################################

## Library Procedure: Window

proc ::Window {args} {
## This procedure may be used free of restrictions.

## Exception added by Christian Gavin on 08/08/02.
## Other packages and widget toolkits have different licensing requirements.
## Please read their license agreements for details.

global vTcl
foreach {cmd name newname} [lrange $args 0 2] {}
set rest [lrange $args 3 end]
if {$name == "" || $cmd == ""} { return }
if {$newname == ""} { set newname $name }
if {$name == "."} { wm withdraw $name; return }
set exists [winfo exists $newname]
switch $cmd {
show {
if {$exists} {
wm deiconify $newname
} elseif {[info procs vTclWindow$name] != ""} {
eval "vTclWindow$name $newname $rest"
}
if {[winfo exists $newname] && [wm state $newname] == "normal"} {
vTcl:FireEvent $newname <>
}
}
hide {
if {$exists} {
wm withdraw $newname
vTcl:FireEvent $newname <>
return}
}
iconify { if $exists {wm iconify $newname; return} }
destroy { if $exists {destroy $newname; return} }
}
}
############################################
## Library Procedure: vTcl:DefineAlias

proc ::vTcl:DefineAlias {target alias widgetProc top_or_alias cmdalias} {
## This procedure may be used free of restrictions.

## Exception added by Christian Gavin on 08/08/02.
## Other packages and widget toolkits have different licensing requirements.
## Please read their license agreements for details.

global widget
set widget($alias) $target
set widget(rev,$target) $alias
if {$cmdalias} {
interp alias {} $alias {} $widgetProc $target
}
if {$top_or_alias != ""} {
set widget($top_or_alias,$alias) $target
if {$cmdalias} {
interp alias {} $top_or_alias.$alias {} $widgetProc $target
}
}
}
#########################################
## Library Procedure: vTcl:DoCmdOption

proc ::vTcl:DoCmdOption {target cmd} {
## This procedure may be used free of restrictions.

## Exception added by Christian Gavin on 08/08/02.
## Other packages and widget toolkits have different licensing requirements.
## Please read their license agreements for details.

## menus are considered toplevel windows

set parent $target
while {[winfo class $parent] == "Menu"} {
set parent [winfo parent $parent]
}

regsub -all {\%widget} $cmd $target cmd
regsub -all {\%top} $cmd [winfo toplevel $parent] cmd

uplevel #0 [list eval $cmd]
}
###########################################
## Library Procedure: vTcl:FireEvent

proc ::vTcl:FireEvent {target event {params {}}} {
## This procedure may be used free of restrictions.

## Exception added by Christian Gavin on 08/08/02.
## Other packages and widget toolkits have different licensing requirements.
## Please read their license agreements for details.

## The window may have disappeared

if {![winfo exists $target]} return
## Process each binding tag, looking for the event
foreach bindtag [bindtags $target] {
set tag_events [bind $bindtag]
set stop_processing 0
foreach tag_event $tag_events {
if {$tag_event == $event} {
set bind_code [bind $bindtag $tag_event]
foreach rep "\{%W $target\} $params" {
regsub -all [lindex $rep 0] $bind_code [lindex $rep 1] bind_code
}
set result [catch {uplevel #0 $bind_code} errortext]
if {$result == 3} {
## break exception, stop processing

set stop_processing 1
} elseif {$result != 0} {
bgerror $errortext
}
break
}
}
if {$stop_processing} {break}
}
}
###################################################
## Library Procedure: vTcl:Toplevel:WidgetProc

proc ::vTcl:Toplevel:WidgetProc {w args} {
## This procedure may be used free of restrictions.

## Exception added by Christian Gavin on 08/08/02.
## Other packages and widget toolkits have different licensing requirements.
## Please read their license agreements for details.

if {[llength $args] == 0} {
## If no arguments, returns the path the alias points to

return $w
}
set command [lindex $args 0]
set args [lrange $args 1 end]
switch -- [string tolower $command] {
"setvar" {
foreach {varname value} $args {}
if {$value == ""} {
return [set ::${w}::${varname}]
} else {
return [set ::${w}::${varname} $value]
}
}
"hide" - "show" {
Window [string tolower $command] $w
}
"showmodal" {
## modal dialog ends when window is destroyed

Window show $w; raise $w
grab $w; tkwait window $w; grab release $w
}
"startmodal" {
## ends when endmodal called

Window show $w; raise $w
set ::${w}::_modal 1
grab $w; tkwait variable ::${w}::_modal; grab release $w
}
"endmodal" {
## ends modal dialog started with startmodal, argument is var name

set ::${w}::_modal 0
Window hide $w
}
default {
uplevel $w $command $args
}
}
}
#####################################################
## Library Procedure: vTcl:WidgetProc

proc ::vTcl:WidgetProc {w args} {
## This procedure may be used free of restrictions.

## Exception added by Christian Gavin on 08/08/02.
## Other packages and widget toolkits have different licensing requirements.
## Please read their license agreements for details.

if {[llength $args] == 0} {
## If no arguments, returns the path the alias points to

return $w
}

set command [lindex $args 0]
set args [lrange $args 1 end]
uplevel $w $command $args
}
####################################################
## Library Procedure: vTcl:toplevel

proc ::vTcl:toplevel {args} {
## This procedure may be used free of restrictions.

## Exception added by Christian Gavin on 08/08/02.
## Other packages and widget toolkits have different licensing requirements.
## Please read their license agreements for details.

uplevel #0 eval toplevel $args
set target [lindex $args 0]
namespace eval ::$target {set _modal 0}
}
}

if {[info exists vTcl(sourcing)]} {

proc vTcl:project:info {} {
set base .top49
namespace eval ::widgets::$base {
set set,origin 1
set set,size 1
set runvisible 1
}
namespace eval ::widgets::$base.but50 {
array set save {-command 1 -disabledforeground 1 -text 1}
}
namespace eval ::widgets::$base.but51 {
array set save {-disabledforeground 1 -text 1}
}
namespace eval ::widgets::$base.ent52 {
array set save {-background 1 -disabledforeground 1 -insertbackground 1 -textvariable 1}
}
namespace eval ::widgets_bindings {
set tagslist _TopLevel
}
namespace eval ::vTcl::modules::main {
set procs {
init
main
}
set compounds {
}
set projectType single
}
}
}

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

# USER DEFINED PROCEDURES
#
####################################
## Procedure: main

proc ::main {argc argv} {}

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

## Initialization Procedure: init

proc ::init {argc argv} {}

init $argc $argv

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

# VTCL GENERATED GUI PROCEDURES
#

proc vTclWindow. {base} {
if {$base == ""} {
set base .
}
###################
# CREATING WIDGETS
###################
wm focusmodel $top passive
wm geometry $top 1x1+0+0; update
wm maxsize $top 3485 1070
wm minsize $top 1 1
wm overrideredirect $top 0
wm resizable $top 1 1
wm withdraw $top
wm title $top "vtcl.tcl #2"
bindtags $top "$top Vtcl.tcl all"
vTcl:FireEvent $top <>
wm protocol $top WM_DELETE_WINDOW "vTcl:FireEvent $top <>"

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

# SETTING GEOMETRY
###################

vTcl:FireEvent $base <>
}

proc vTclWindow.top49 {base} {
if {$base == ""} {
set base .top49
}
if {[winfo exists $base]} {
wm deiconify $base; return
}
set top $base
###################
# CREATING WIDGETS
###################
vTcl:toplevel $top -class Toplevel
wm focusmodel $top passive
wm geometry $top 609x422+2205+586; update
wm maxsize $top 3485 1070
wm minsize $top 1 1
wm overrideredirect $top 0
wm resizable $top 1 1
wm deiconify $top
wm title $top "New Toplevel 1"
vTcl:DefineAlias "$top" "Toplevel1" vTcl:Toplevel:WidgetProc "" 1
bindtags $top "$top Toplevel all _TopLevel"
vTcl:FireEvent $top <>
wm protocol $top WM_DELETE_WINDOW "vTcl:FireEvent $top <>"

button $top.but50 \
-disabledforeground #a1a1a1 -text add
vTcl:DefineAlias "$top.but50" "Button1" vTcl:WidgetProc "Toplevel1" 1
button $top.but51 \
-disabledforeground #a1a1a1 -text del
vTcl:DefineAlias "$top.but51" "Button2" vTcl:WidgetProc "Toplevel1" 1
entry $top.ent52 \
-background white -disabledforeground #a1a1a1 -insertbackground black \
-textvariable "$top\::ent52"
vTcl:DefineAlias "$top.ent52" "Entry1" vTcl:WidgetProc "Toplevel1" 1
###################
# SETTING GEOMETRY
###################
place $top.but50 \
-in $top -x 145 -y 60 -width 66 -height 28 -anchor nw \
-bordermode ignore
place $top.but51 \
-in $top -x 230 -y 60 -width 68 -height 28 -anchor nw \
-bordermode ignore
place $top.ent52 \
-in $top -x 145 -y 95 -width 258 -height 22 -anchor nw \
-bordermode ignore

vTcl:FireEvent $base <>
}

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

## Binding tag: _TopLevel

bind "_TopLevel" <> {
if {![info exists _topcount]} {set _topcount 0}; incr _topcount
}
bind "_TopLevel" <> {
if {[set ::%W::_modal]} {
vTcl:Toplevel:WidgetProc %W endmodal
} else {
destroy %W; if {$_topcount == 0} {exit}
}
}
bind "_TopLevel" {
if {[winfo toplevel %W] == "%W"} {incr _topcount -1}
}

Window show .
Window show .top49

main $argc $argv