Vous êtes sur la page 1sur 3

Tk Assignment-2

Q1. Write a script to implement the clock widget.


Ans:-
#!/bin/usr/wish
global a
set t [clock format [clock seconds] -format %T]
label .l1 -text "Time" -bg black -fg red
label .l2 -text "$t" -textvariable a -fg red -bg grey
pack .l1 .l2 -side top -padx 10 -pady 10 -anchor s

after 10 p

proc p {} {
global a
set a [clock format [clock seconds] -format %T]
after 10 p
}
Output:-

Q2.Write a script to implement scrollbar in x and y co-ordinates.


Ans:-
#!/usr/bin/wish
text .t -width 20 -height 4 -wrap none
scrollbar .yx -command [list .t yview] -orient vertical -bg red
scrollbar .xx -command [list .t xview] -orient horizontal -bg red
pack .yx -side right -fill y -expand 0
pack .xx -side bottom -fill x -expand 0
pack .t -expand 1 -side left -fill both
.t configure -yscrollcommand [list .yx set]
.t configure -yscrollcommand [list .xx set]

Output:-

Q3. Write a script to implement the entry widget.


Ans:-
#!/usr/bin/wish
radiobutton .r1 -text "1.Human" -variable var -value 2 -command { set n 2} -bg red -fg blue
radiobutton .r2 -text "2.Dog" -variable var -value 4 -command { set n 4 } -bg red -fg blue
radiobutton .r3 -text "3.Chair" -variable var -value 5 -command {set n 5} -bg red -fg blue

label .l1 -text "No. of legs:" -bg blue -fg red


entry .e1 -text n -bg yellow
pack .r1 .r2 .r3 -padx 10 -pady 10 -anchor nw
pack .l1 .e1 -side left

Output:-

Q4.Write a script to hide password.


Ans:-
#!/bin/tcl
set n 7
puts "enter password:"
for {set i 0} {$i<$n} {incr i} {
exec stty -echo
set char [read stdin 1]
exec stty echo
puts -nonewline "*"
set pass [append pass $char]
}
puts ""
puts "your password:$pass"
unset pass

Output:-
Q5. Write a s

Vous aimerez peut-être aussi