SlipKnot
December 9th, 2005, 04:14 PM
This is using the TK library, I'm still leraning, so don't laught.
http://img214.imageshack.us/img214/3401/tktut9yh.png
# this is always needed for a Tk aplication
require "tk"
# Our main window:
main = TkRoot.new{title "Tk example"}
# Instance variable
@var1 = TkVariable.new
# A label with text "Check:"
label1 = TkLabel.new(main,'text'=>"Check:")
# A check button
check1 = TkCheckButton.new(main,'variable'=>@var1)
# Packing the first label and the check button
[label1,check1].each{|obj|
obj.pack('side'=>'left','padx'=>10,'pady'=>10)}
# Return the state of the check button
def check_var
case @var1#.value
when 0 then return "unchecked"
when 1 then return "checked" end
end
# Another label, it shows the state of the check button
label2 = TkLabel.new(main,'text'=>"none")
# This button update the "label2"
but1 = TkButton.new(main,'text'=>"Show Check",
'command'=>proc{
label2.configure('text'=>check_var) }
)
# Packing the second label and the normal button
[label2,but1].each{|obj|
obj.pack('side'=>'top','pady'=>10,'padx'=>10)}
# Other thing always needed in Tk aplication
Tk.mainloop
http://img214.imageshack.us/img214/3401/tktut9yh.png
# this is always needed for a Tk aplication
require "tk"
# Our main window:
main = TkRoot.new{title "Tk example"}
# Instance variable
@var1 = TkVariable.new
# A label with text "Check:"
label1 = TkLabel.new(main,'text'=>"Check:")
# A check button
check1 = TkCheckButton.new(main,'variable'=>@var1)
# Packing the first label and the check button
[label1,check1].each{|obj|
obj.pack('side'=>'left','padx'=>10,'pady'=>10)}
# Return the state of the check button
def check_var
case @var1#.value
when 0 then return "unchecked"
when 1 then return "checked" end
end
# Another label, it shows the state of the check button
label2 = TkLabel.new(main,'text'=>"none")
# This button update the "label2"
but1 = TkButton.new(main,'text'=>"Show Check",
'command'=>proc{
label2.configure('text'=>check_var) }
)
# Packing the second label and the normal button
[label2,but1].each{|obj|
obj.pack('side'=>'top','pady'=>10,'padx'=>10)}
# Other thing always needed in Tk aplication
Tk.mainloop