Posted to tcl by oldlaptop at Sun Aug 29 04:29:47 GMT 2021view raw

  1. #! /usr/bin/env tclsh
  2.  
  3. package require Tk 8.5
  4.  
  5. proc calculate {} {
  6. set ::cel [expr {($::fahr - 32) * 5.0 / 9.0}]
  7. }
  8.  
  9. ttk::frame .f
  10.  
  11. ttk::label .f.fahrlab -text Fahrenheit
  12. ttk::entry .f.fahren -textvariable ::fahr
  13.  
  14. ttk::label .f.cellab -text Celsius
  15. ttk::entry .f.celen -textvariable ::cel -state readonly
  16.  
  17. ttk::button .f.calc -text Calculate! -command calculate -width 0
  18.  
  19. # The layout code looks way too obvious to work! And yet it does.
  20. grid .f.fahrlab .f.fahren -sticky ew
  21. grid .f.cellab .f.celen -sticky ew
  22. grid x .f.calc -sticky se
  23.  
  24. grid rowconfigure .f 2 -weight 1
  25. grid columnconfigure .f 1 -weight 1
  26.  
  27. grid .f -sticky nsew
  28. grid rowconfigure . 0 -weight 1
  29. grid columnconfigure . 0 -weight 1
  30.