Open web page from Ruby Tk app

All,

I’m trying to avoid using TkHTML (too many dependencies in a
cross-platform app).

I just want to click on a “link” (maybe a TkLabel with text underlined
and in blue) … and open a URL in a web page.

  • Does anyone have some sample code for opening a web page in the OS’s
    default browser?
  • also, does anyone have any sample code on executing a proc on mouse
    down in a TKlabel?

any help is appreciated.

Etienne

e deleflie wrote:

  • also, does anyone have any sample code on executing a proc on mouse
    down in a TKlabel?

require ‘tk’

def on_button_press(e)
widget = e.widget
xcoord = e.x
ycoord = e.y

puts “button pressed, x:#{xcoord}, y:#{ycoord}”
end

root = TkRoot.new {
title ‘Label Test’
geometry “600x400+200+50”
}

label = TkLabel.new(root) do
text “click me”
pack
end

label.bind(‘ButtonPress-1’, lambda {|e| on_button_press(e)})
label.bind(“ButtonRelease-1”, proc{puts “button released”})

Tk.mainloop