Experimento con Tcl/Tk

Primera ventana de la aplicación

 

Segunda ventana, si antes escribimos «4» y pulsamos el botón


toplevel .tablero -width 300 -height 80
frame .tablero.izquierda -width 100 -height 300
frame .tablero.derecha -width 50 -height 300
frame .tablero.boton -width 50 -height 300

label .tablero.izquierda.etiqueta1 -text «TABLERO: »
entry .tablero.derecha.tamanyo -width 50
button .tablero.boton.enviar -text «Enviar» -command { Enviar }

proc centre_window {ventana {width 300} {height 80} } {
set x [expr { ( [winfo vrootwidth $ventana] – $width ) / 2 }]
set y [expr { ( [winfo vrootheight $ventana] – $height ) / 2 }]
wm geometry $ventana ${width}x${height}+${x}+${y}
}

centre_window .tablero 300 80

wm resizable .tablero 0 0

pack .tablero.izquierda -side left -padx 10 -pady 10
pack .tablero.izquierda.etiqueta1 -ipadx 10 -ipady 10
pack .tablero.boton -side right
pack .tablero.boton.enviar -padx 10 -pady 20
pack .tablero.derecha -side right
pack .tablero.derecha.tamanyo -padx 10 -pady 20

proc Enviar { } {

set tamano [.tablero.derecha.tamanyo get ]

destroy .tablero
destroy .tablero.derecha.tamanyo
destroy .tablero.derecha
destroy .tablero.boton.enviar
destroy .tablero.boton
destroy .tablero.izquierda.etiqueta1
destroy .tablero.izquierda

toplevel .tablero

proc centre_window {tabla {width 50} {height 50} } {
set x [expr { ( [winfo vrootwidth $tabla] – $width ) / 2 }]
set y [expr { ( [winfo vrootheight $tabla] – $height ) / 2 }]
wm geometry $tabla ${width}x${height}+${x}+${y}
}

set lado [expr {$tamano*50} ]

centre_window .tablero $lado $lado

wm resizable .tablero 0 0

for {set m 0} {$m<$tamano} {incr m 1} {
frame .tablero.$m  
pack .tablero.$m -side top -fill x 
for {set n 0} {$n<$tamano} {incr n 1} { 
frame .tablero.$m.$n -width 50 -height 50 -bg grey -relief groove -borderwidth 7 
pack .tablero.$m.$n -side left 
set w .tablero.$m.$n 
bind $w  { puts «hola» }
}
}

}

Write a Reply or Comment

Your email address will not be published.