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

  1. package require Tk
  2.  
  3. wm title . "Convert"
  4.  
  5. grid [ttk::frame .f -padding "3 3 12 12"] -column 0 -row 0 -sticky nwes
  6. grid columnconfigure . 0 -weight 1; grid rowconfigure . 0 -weight 1
  7. grid [ttk::label .f.text -textvariable output ] -column 4 -row 1 -sticky nwes
  8. grid [ttk::entry .f.inp -textvariable input] -column 1 -row 1 -sticky e
  9. set combo [ttk::combobox .f.cbox -values [list pounds-to-kilos kilo-to-pounds miles-to-km] -textvariable box]
  10. grid $combo -column 2 -row 1 -sticky we
  11. grid [ttk::button .f.btn -text "Run!" -command exe-func] -column 3 -row 1 -sticky we
  12.  
  13.  
  14.  
  15. bind . <Control-c> {get-current}
  16. bind . <Control-q> {exit}
  17.  
  18. proc get-current {} {
  19. puts [.f.cbox get]
  20. puts $::input
  21. }
  22.  
  23. proc exe-func {} {
  24. set $::output [$::box get]
  25. }
  26.  
  27.  
  28. proc pounds-to-kilos {} {
  29. set pounds $::input
  30. set ::output [format "%.2f" [expr (($pounds*10000)/2.20462)/10000]]
  31. }
  32.  
  33. proc miles-to-km {} {
  34. set ::output [expr ($::input*10)*1.6/10]
  35. }
  36.  
  37. proc kilo-to-pounds {} {
  38. set kilo $::input
  39. set ::output [format "%.2f" [expr (($kilo*1000)/0.453624)/1000]]
  40. }
  41.  
  42.  
  43.  

Add a comment

Please note that this site uses the meta tags nofollow,noindex for all pages that contain comments.
Items are closed for new comments after 1 week