Posted to tcl by iobates at Sat Aug 08 00:30:11 GMT 2026view pretty

package require Tk

wm title . "Convert"

grid [ttk::frame .f -padding "3 3 12 12"] -column 0 -row 0 -sticky nwes
grid columnconfigure . 0 -weight 1; grid rowconfigure . 0 -weight 1
grid [ttk::label .f.text -textvariable output ] -column 4 -row 1 -sticky nwes
grid [ttk::entry .f.inp -textvariable input] -column 1 -row 1 -sticky e
set combo [ttk::combobox .f.cbox -values [list pounds-to-kilos kilo-to-pounds miles-to-km] -textvariable box]
grid $combo -column 2 -row 1 -sticky we
grid [ttk::button .f.btn -text "Run!" -command exe-func] -column 3 -row 1 -sticky we



bind . <Control-c> {get-current}
bind . <Control-q> {exit}

proc get-current {} {
    puts [.f.cbox get]
    puts $::input
}

proc exe-func {} {
    set $::output [$::box get]
}


proc pounds-to-kilos {} {
    set pounds $::input
    set ::output [format "%.2f" [expr (($pounds*10000)/2.20462)/10000]]
}

proc miles-to-km {} {
    set ::output [expr ($::input*10)*1.6/10]
}

proc kilo-to-pounds {} {
    set kilo $::input
    set ::output [format "%.2f" [expr (($kilo*1000)/0.453624)/1000]]
}