open web page from Ruby Tk app

E

e deleflie

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
 
7

7stud --

e said:
- 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,204
Messages
2,571,065
Members
47,672
Latest member
svaraho

Latest Threads

Top