C
csjasnoch
So I found this simple code for using a button with a picture..
require 'tk'
def doit
puts "Want to change image and set some flags here....\n"
end
class Picture
def initialize(root)
image1 = TkPhotoImage.new { file "light_on.gif" }
image2 = TkPhotoImage.new { file "light_off2.gif" }
b = TkButton.new(root) {
image image1
command proc {self.doit} }
b.bind("Enter") { b.configure('image'=>image2) }
b.bind("Leave") { b.configure('image'=>image1) }
b.pack('side'=>'left', 'padx'=>10, 'pady'=>10)
end
end
parent = TkRoot.new{ title 'Pictures' }
Picture.new(parent)
Tk.mainloop
I dont really care about the Enter/Leave imaging. But rather I want it
to change image when it is clicked...
Is there something to pass it (like "Clicked" ) that would bind when it
is clicked?
But ideally I want to be able to check a current status variable and
depending on the variable image becomes one or the other. It is for a
light switch (thus the files are named "light_on" etc).
require 'tk'
def doit
puts "Want to change image and set some flags here....\n"
end
class Picture
def initialize(root)
image1 = TkPhotoImage.new { file "light_on.gif" }
image2 = TkPhotoImage.new { file "light_off2.gif" }
b = TkButton.new(root) {
image image1
command proc {self.doit} }
b.bind("Enter") { b.configure('image'=>image2) }
b.bind("Leave") { b.configure('image'=>image1) }
b.pack('side'=>'left', 'padx'=>10, 'pady'=>10)
end
end
parent = TkRoot.new{ title 'Pictures' }
Picture.new(parent)
Tk.mainloop
I dont really care about the Enter/Leave imaging. But rather I want it
to change image when it is clicked...
Is there something to pass it (like "Clicked" ) that would bind when it
is clicked?
But ideally I want to be able to check a current status variable and
depending on the variable image becomes one or the other. It is for a
light switch (thus the files are named "light_on" etc).