1 2 3 4 5 6 7 8 9 10 11 12 | #!/usr/bin/wish # # Hello World, Tk-style button .hello -text Hello \ -command {puts stdout \ "Hello, World!"} button .goodbye -text Bye! \ -command {exit} pack .hello -padx 60 -pady 5 pack .goodbye -padx 60 -pady 5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ~/tcltk$ wish % . configure -width 200 -height 400 % label .header -text "Tk Tutorial Example" .header % place .header -x 5 -y 2 % scale .slider -from 1 -to 100 -orient horiz .slider % .slider configure -variable SlidVal % place .slider -x 5 -y 20 % entry .slidbox -width 5 -textvariable SlidVal .slidbox % place .slidbox -x 120 -y 38 % radiobutton .one -text "Don't Worry" -variable Mood -value 1 .one % radiobutton .two -text "Be Happy" -variable Mood -value 2 .two % place .one -x 5 -y 70 % place .two -x 5 -y 90 % text .twindow -width 22 -height 14 -font {clean -14} .twindow % place .twindow -x 5 -y 120 % button .ok -command {process_data $SlidVal} -text "OK" .ok % button .cancel -command {exit} -text "Cancel" -background red .cancel % place .ok -x 15 -y 350 % place .cancel -x 120 -y 350 |
1 2 3 4 5 6 7 | # ~/.netsetrc # 03.26.2001 bilbrey # space between name and command Home /usr/local/bin/nethome Office /usr/local/bin/netoffice Admin /usr/local/bin/netadmin |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #!/usr/bin/wish # # netset.tcl # 03.26.2001 bilbrey set ConFile "~/.netsetrc" if [catch {open $ConFile r} Conf] { puts stderr "Open $ConFile failed" return 1 } # parse config, define buttons set Bcount 0 while {[gets $Conf Cline] >= 0} { if {1 == [string match #* $Cline]} continue if {[string length $Cline] < 4} continue set Nend [string wordend $Cline 0] incr Nend -1 set Bname [string range $Cline 0 $Nend] set Cbeg [expr $Nend + 2] set Bcomd "exec " append Bcomd [string range $Cline $Cbeg end] incr Bcount set NextBut "button$Bcount" button .$NextBut -text $Bname -command $Bcomd } if {$Bcount == 1} { puts stderr "No buttons defined" return 2 } # display buttons while {$Bcount >= 1} { set NextBut "button$Bcount" pack .$NextBut -padx 10 -pady 10 incr Bcount -1 } button .exit -text Exit -command {exit} pack .exit -padx 10 -pady 10 |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |