检测点击 TkText 中的 TkTextImage
Detect click on a TkTextImage inside TkText
我想将一个事件,特别是 Button-1
绑定到 TkTextImage
,它被放置在 TkText
中。但是,该事件永远不会触发。我已经尝试了其他事件,例如 Enter
和 Leave
,但这些事件也没有被触发。
图像显示正确,但它没有触发任何事件。
我正在使用以下代码:
root = TkRoot.new(title: 'Hello, world!')
img = TkPhotoImage.new(file: 'test.gif')
text = TkText.new(root)
text.pack
text_image = TkTextImage.new(text, '0.0', image: img)
text_image.bind("Button-1", proc do
puts "Image click!"
end)
puts "Running app..."
Tk.mainloop
如何启用我的 text_image
来检测事件?
这不是直接的解决方案。
使用 TkTextWindow 和 TkButton 怎么样?
require 'tk'
src = TkScrollbar.new.pack(side: :right, fill: :y)
text = TkText.new.pack(side: :left, fill: :both, expand: true)
text.yscrollbar src
img = TkPhotoImage.new(file: 'test.gif')
button= TkButton.new(image: img) do
relief :flat
command {puts "Image click!"}
end
TkTextWindow.new(text, '0.0').window=button
Tk.mainloop
我想将一个事件,特别是 Button-1
绑定到 TkTextImage
,它被放置在 TkText
中。但是,该事件永远不会触发。我已经尝试了其他事件,例如 Enter
和 Leave
,但这些事件也没有被触发。
图像显示正确,但它没有触发任何事件。
我正在使用以下代码:
root = TkRoot.new(title: 'Hello, world!')
img = TkPhotoImage.new(file: 'test.gif')
text = TkText.new(root)
text.pack
text_image = TkTextImage.new(text, '0.0', image: img)
text_image.bind("Button-1", proc do
puts "Image click!"
end)
puts "Running app..."
Tk.mainloop
如何启用我的 text_image
来检测事件?
这不是直接的解决方案。 使用 TkTextWindow 和 TkButton 怎么样?
require 'tk'
src = TkScrollbar.new.pack(side: :right, fill: :y)
text = TkText.new.pack(side: :left, fill: :both, expand: true)
text.yscrollbar src
img = TkPhotoImage.new(file: 'test.gif')
button= TkButton.new(image: img) do
relief :flat
command {puts "Image click!"}
end
TkTextWindow.new(text, '0.0').window=button
Tk.mainloop