ihm avec tcl tk
ihm avec tcl tk
Langage de Script TCL
- TCL = Langage de Script ( Langage Interprété )
- TK = Bibliothèque GUI
Recopie d’un Message
|
|
#! /usr/bin/wish
########################################################################
# UI
########################################################################
wm title . "Copy String"
label .labelSource -text "Source"
entry .sourceEnt -width 25 -textvariable source
button .copyButton -text copy
label .labelDestination -text "Destination"
entry .destinationEnt -width 25 -textvariable destination
grid .labelSource .sourceEnt -row 0 -pady 4 -sticky e
grid .copyButton -row 1 -pady 4 -sticky e
grid .labelDestination .destinationEnt -row 2 -pady 4 -sticky e
bind .copyButton <ButtonPress-1> copySource
########################################################################
# PROC
########################################################################
proc copySource {} {
.destinationEnt delete 0 end
# Write in terminal :
puts "copy button pressed"
# [] : Interpolation (instructions imbriquées) :
.destinationEnt insert 0 [ .sourceEnt get ]
.sourceEnt delete 0 end
}
########################################################################
Chronomètre
|
|
#! /usr/bin/wish
########################################################################
# UI
########################################################################
button .start -text Start -command Start
label .time -textvar time -width 9 -bg black -fg green
set time 00:00.00
button .stop -text Stop -command Stop
button .reset -text Reset -command Reset
eval pack [winfo children .] -side left -fill y
########################################################################
# PROC
########################################################################
proc every {ms body} {
eval $body; after $ms [info level 0]
}
proc Start {} {
if {$::time=="00:00.00"} {
set ::time0 [clock clicks -milliseconds]
}
every 10 {
set m [expr {[clock clicks -milliseconds] - $::time0}]
set ::time [format %2.2d:%2.2d.%2.2d \
[expr {$m/60000}] [expr {($m/1000)%60}] [expr {$m%1000/10}]]
}
.start config -state disabled
}
proc Stop {} {
if {[llength [after info]]} {
after cancel [after info]
} else {set ::time 00:00.00}
.start config -state normal
}
proc Reset {} {
after cancel [after info]
set ::time 00:00.00
.start config -state normal
}
########################################################################
TCL-TK et laison série UART (RS232)
|
|
#! /usr/bin/wish
set SerialPort /dev/ttyACM0
set SerialMode "115200,n,8,1"
set chan [open $SerialPort r+]
fconfigure $chan -mode $SerialMode -translation binary -buffering none -blocking 0
fileevent $chan readable [list receiveMessage $chan]
########################################################################
# UI
########################################################################
wm title . "Serial ihm"
label .labelToSendMes -text "Message to Send"
entry .toSendEntry -width 25
button .sendMessageButton -text Send
label .labelReceivedMes -text "Received Message"
entry .receivedEntry -width 25
pack .labelToSendMes .toSendEntry .sendMessageButton .labelReceivedMes .receivedEntry
bind .sendMessageButton <ButtonPress-1> [list sendMessage $chan]
########################################################################
# PROC
########################################################################
proc sendMessage {chan} {
puts $chan [ .toSendEntry get ]
flush $chan
.toSendEntry delete 0 end
}
proc receiveMessage {chan} {
set data [read $chan]
set size [string length $data]
puts "received $size bytes: $data"
.receivedEntry delete 0 end
.receivedEntry insert @0 $data
}
########################################################################